variable.php 15.4 KB
Newer Older
imac's avatar
imac committed
1
<?php
2
//print_r($_GET);
imac's avatar
imac committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/**
 * Variable product add to cart
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/variable.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see 	https://docs.woocommerce.com/document/template-structure/
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 3.0.0
 */
Nahla Shiri's avatar
Nahla Shiri committed
19 20
if (!defined('ABSPATH')) {
    exit;
imac's avatar
imac committed
21 22 23 24
}

global $product;

Nahla Shiri's avatar
Nahla Shiri committed
25
$attribute_keys = array_keys($attributes);
imac's avatar
imac committed
26

27 28
$product_cats = wp_get_post_terms($product->get_id(), 'product_cat');

Nahla Shiri's avatar
Nahla Shiri committed
29
$subcat_iD = $product_cats[1]->term_id;
Nahla Shiri's avatar
Nahla Shiri committed
30
$current_variationID = $_GET['variation_id'];
Nahla Shiri's avatar
Nahla Shiri committed
31

Nahla Shiri's avatar
Nahla Shiri committed
32 33
if (!function_exists('print_attribute_radio')) {

34 35
    function print_attribute_radio($checked_value, $value, $label, $name, $index=0) {
       
Nahla Shiri's avatar
Nahla Shiri committed
36
        $current_color = $_GET['attribute_couleur'];
37 38
        $selected = $default_checked = "";
        if ($value == strtolower($current_color)){
Nahla Shiri's avatar
Nahla Shiri committed
39
            $default_checked = "checked";
40 41 42
            $selected = "selected";
        }
           
Nahla Shiri's avatar
Nahla Shiri committed
43
        $checked = sanitize_title($checked_value) === $checked_value ? checked($checked_value, sanitize_title($value), false) : checked($checked_value, $value, false);
Nahla Shiri's avatar
Nahla Shiri committed
44

Nahla Shiri's avatar
Nahla Shiri committed
45 46 47 48 49 50 51 52 53
        $input_name = 'attribute_' . esc_attr($name);

        $esc_value = esc_attr($value);
        $id = esc_attr($name . '_v_' . $value);
        if ($name == 'pa_couleur') {
            $hexa = nap_color_attribute($value);
            $filtered_label = apply_filters('woocommerce_variation_option_name', $label);
            printf(' <style>
                        #' . $id . ':after { background-color: ' . $hexa . '; }
54 55
                    </style><li class="color-list '.$selected.' " data-color="' . $hexa . '">
                    <input data-color="' . $hexa . '" type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s ' . $default_checked . '></li>', $input_name, $esc_value, $id, $checked, $filtered_label);
Nahla Shiri's avatar
Nahla Shiri committed
56 57
        } else {
            $icons = nap_icon_format($value);
58 59 60 61
            
                $format_img='<img src="'.$icons['inactive'].'" data-img = "'.$icons['inactive'].'" data-img-active = "'.$icons['active'].'" id="format_'.$index.'">';
            
            
Nahla Shiri's avatar
Nahla Shiri committed
62
            $filtered_label = apply_filters('woocommerce_variation_option_name', $label);
63
            printf('<li class="format-list selected"><input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s>
64

65
                <label class="format-label" for="%3$s">'.$format_img.'</label>
66 67
                <div class="format-desc">'.$value.'</span>
                </li>', $input_name, $esc_value, $id, $checked, $filtered_label); //<label class="format-label" style="background:url(' . $icons['inactive'] . ')" for="%3$s"></label>
Nahla Shiri's avatar
Nahla Shiri committed
68 69 70
        }
    }

71
}   
Nahla Shiri's avatar
Nahla Shiri committed
72 73 74

do_action('woocommerce_before_add_to_cart_form');
?>
Nahla Shiri's avatar
Nahla Shiri committed
75 76

<div id="product" class="clearfix">
Nahla Shiri's avatar
Nahla Shiri committed
77
    <div class="product-images row animated">
78
        <div class = "btn-wrapper row close-panel">
Nahla Shiri's avatar
Nahla Shiri committed
79 80
            <div class="pink-btn circle-btn"><a href="#"><span class = "abs-center backlink">Retour</span></a></div>
        </div>
81
        <div class="product-slides row">
Nahla Shiri's avatar
Nahla Shiri committed
82
            <div class="product-header">
Nahla Shiri's avatar
Nahla Shiri committed
83
                <h2 class="crete -italic font-small"><?php echo $product_cats[1]->name ?></h2>
84
                <h3 class="crete"><?php the_title();?></h3>
Nahla Shiri's avatar
Nahla Shiri committed
85
            </div>
86 87 88 89 90 91 92 93 94 95
            <div class="slides-wrapper center">
                <div class="row">
                    <div class="nav-slider transition">
                        <ul>
                            <li id = "mozaique"><span class="icon mozaique row"></span><span class="desc">Mozaïque</span></li>
                            <li id = "zoom" data-active="false" ><span class="icon zoom"></span><span class="desc">Zoom</span></li>
                            <li><span class="icon download"></span><span class="desc">Télécharger</span></li>
                        </ul>
                    </div>
                    <div id="slides"> 
Nahla Shiri's avatar
Nahla Shiri committed
96
                        <?php
97 98 99
                        $variations = $product->get_available_variations();
                        $var_colors = nap_distinct_color_variations($variations);
                        foreach ($var_colors as $key => $value) :
Nahla Shiri's avatar
Nahla Shiri committed
100
                            ?>
101 102 103
                            <div style="background-image:url('<?php echo get_the_post_thumbnail_url($key, 'medium') ?>')" class="image element-slider  easyzoom easyzoom--overlay easyzoom--with-toggle" data-color = "<?php echo $value ?>" data-slick-index = "1">
                                <a href="<?php echo get_the_post_thumbnail_url($key, 'full') ?>">
                                    <!--<img src="<?php echo get_the_post_thumbnail_url($key, 'medium') ?>" alt="" />-->
Nahla Shiri's avatar
Nahla Shiri committed
104 105 106 107
                                </a>
                            </div>

                            <?php
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
                        endforeach;
                        ?>

                        <?php
                        if (get_field('images_ambiance', 'product_cat_' . $subcat_iD)):
                            $ambiance = array();
                            while (has_sub_field('images_ambiance', 'product_cat_' . $subcat_iD)) :
                                $image_amb = get_sub_field('img_ab');
                                $ambiance [] = $image_amb;
                                $attachment = wp_get_attachment_image_src($image_amb, 'medium');
                                $hd = wp_get_attachment_image_src($image_amb, 'full');
                                ?>
                                <div  style="background-image:url('<?php echo $attachment[0]; ?>')" class="image element-slider  easyzoom easyzoom--overlay easyzoom--with-toggle" data-color = "<?php echo $color ?>" data-slick-index = "1">
                                    <a href="<?php echo $hd[0]; ?>">
                                        <!--<img src="<?php echo $attachment[0]; ?>" alt="" />-->
                                    </a>
                                </div>

                                <?php
                            endwhile;
                        endif;
                        ?>
Nahla Shiri's avatar
Nahla Shiri committed
130

131 132
                    </div>  
                </div>
Nahla Shiri's avatar
Nahla Shiri committed
133 134 135 136 137 138 139 140 141 142 143 144 145
                <div class="gallery clearfix">
                    <div class="gallery-content clearfix">
                        <span class="close-btn"></span>

                        <?php foreach ($var_colors as $key => $value) : ?>
                            <article class = "row" data-color = "<?php echo $value; ?>">
                                <a href="<?php echo get_the_post_thumbnail_url($key, 'full') ?>"></a>
                                <figure>
                                    <img src="<?php echo get_the_post_thumbnail_url($key, 'medium') ?>" alt="" title="">
                                </figure>
                            </article>
                            <?php
                        endforeach;
146 147 148 149 150
                        if(!empty($ambiance)):
                            foreach ($ambiance as $key => $value) :
                                $attachment = wp_get_attachment_image_src($value, 'medium');
                                $hd = wp_get_attachment_image_src($value, 'full');
                                ?>
Nahla Shiri's avatar
Nahla Shiri committed
151

152 153 154 155 156 157 158 159 160 161
                                <article class = "row" data-color = "red">
                                    <a class = "download-btn" href="<?php echo $hd[0]; ?>" download></a>
                                    <figure>
                                        <img src="<?php echo $attachment[0]; ?>" alt="" title="">
                                    </figure>
                                </article>
                            <?php 
                            endforeach;
                        endif;
                        ?>
Nahla Shiri's avatar
Nahla Shiri committed
162 163


Nahla Shiri's avatar
Nahla Shiri committed
164 165
                    </div>
                </div>
Nahla Shiri's avatar
Nahla Shiri committed
166 167
            </div> 
        </div>
Nahla Shiri's avatar
Nahla Shiri committed
168 169 170
    </div>


Nahla Shiri's avatar
Nahla Shiri committed
171 172
    <div class="product-details full-height row right clearfix transition">

Nahla Shiri's avatar
Nahla Shiri committed
173
        <form class="variations_form cart left row" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint($product->get_id()); ?>" data-product_variations="<?php echo htmlspecialchars(wp_json_encode($available_variations)) ?>">
Nahla Shiri's avatar
Nahla Shiri committed
174 175 176 177 178 179
            <?php do_action('woocommerce_before_variations_form'); ?>

            <?php if (empty($available_variations) && false !== $available_variations) : ?>
                <p class="stock out-of-stock"><?php _e('This product is currently out of stock and unavailable.', 'woocommerce'); ?></p>
            <?php else : ?>
                <div class="variations" cellspacing="0">
Nahla Shiri's avatar
Nahla Shiri committed
180 181 182 183
                        
                    <?php 
                    $i=0;
                    foreach ($attributes as $name => $options) : ?>
184
                        <div class="list row <?php echo $name;?> left border-l center">
Nahla Shiri's avatar
Nahla Shiri committed
185 186

                            <div class="product-header center font-small label">
187
                                <label for="<?php echo sanitize_title($name); ?>" class = "chevron bottom"> <?php if($i==0) echo 'choix de la '; else echo 'choix du '; ?><?php echo strtolower(wc_attribute_label($name)); ?></label>
Nahla Shiri's avatar
Nahla Shiri committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
                            </div>
                            <?php
                            $sanitized_name = sanitize_title($name);
                            if (isset($_REQUEST['attribute_' . $sanitized_name])) {
                                $checked_value = $_REQUEST['attribute_' . $sanitized_name];
                            } elseif (isset($selected_attributes[$sanitized_name])) {
                                $checked_value = $selected_attributes[$sanitized_name];
                            } else {
                                $checked_value = '';
                            }
                            ?>
                            <ul class="value">
                                <?php
                                if (!empty($options)) {
                                    if (taxonomy_exists($name)) {
                                        // Get terms if this is a taxonomy - ordered. We need the names too.
                                        $terms = wc_get_product_terms($product->get_id(), $name, array('fields' => 'all'));

206
                                        foreach ($terms as $key=>$term) {
Nahla Shiri's avatar
Nahla Shiri committed
207 208 209
                                            if (!in_array($term->slug, $options)) {
                                                continue;
                                            }
210 211
                                            print_attribute_radio($checked_value, $term->slug, $term->name, $sanitized_name,$key);
                                            
Nahla Shiri's avatar
Nahla Shiri committed
212 213 214 215
                                        }
                                    } else {
                                        foreach ($options as $option) {
                                            print_attribute_radio($checked_value, $option, $option, $sanitized_name);
216
                                           
Nahla Shiri's avatar
Nahla Shiri committed
217 218 219 220 221 222 223 224
                                        }
                                    }
                                }

                                echo end($attribute_keys) === $name ? apply_filters('woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __('Clear', 'woocommerce') . '</a>') : '';
                                ?>
                            </ul>
                        </div>
Nahla Shiri's avatar
Nahla Shiri committed
225
                    <?php $i++;endforeach; ?>
Nahla Shiri's avatar
Nahla Shiri committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

                </div>

                <?php do_action('woocommerce_before_add_to_cart_button'); ?>

                <div class="single_variation_wrap">
                    <?php
                    do_action('woocommerce_before_single_variation');
                    do_action('woocommerce_single_variation');
                    do_action('woocommerce_after_single_variation');
                    ?>
                </div>

                <?php do_action('woocommerce_after_add_to_cart_button'); ?>
            <?php endif; ?>

            <?php do_action('woocommerce_after_variations_form'); ?>

Nahla Shiri's avatar
Nahla Shiri committed
244 245
        </form>
        <div class="product-info row center left border-l">
Nahla Shiri's avatar
Nahla Shiri committed
246
                <div class="info-content">
Nahla Shiri's avatar
Nahla Shiri committed
247

248 249
                    <h2 class = "crete  font-small" ><?php echo $product_cats[1]->name ?></h2>
                    <h3 class = "crete  font-small info-attr" ><span class="info-format"><?php echo $_GET['attribute_format']?></span> <span class="info-color"><?php echo$_GET['attribute_couleur'] ?></span></h3>
Nahla Shiri's avatar
Nahla Shiri committed
250
                    <div class="details font-small">
Nahla Shiri's avatar
Nahla Shiri committed
251 252
                        <p class="info-format-txt"><?php echo $_GET['attribute_format']?></p>
                        <p class="pq"><?php echo nap_variable_meta($current_variationID, 'variation_description'); ?></p>
Nahla Shiri's avatar
Nahla Shiri committed
253 254
                    </div>
                    <div class="price">
Nahla Shiri's avatar
Nahla Shiri committed
255
                        <span class="crete"><?php echo nap_variable_meta($current_variationID, 'price'); ?> € ht</span>
Nahla Shiri's avatar
Nahla Shiri committed
256 257 258
                        <div class="notice">( prix public conseillé )</div>
                        <div class="font-small">
                            <div class="product_meta">
imac's avatar
imac committed
259

Nahla Shiri's avatar
Nahla Shiri committed
260
                                <?php do_action('woocommerce_product_meta_start'); ?>
Nahla Shiri's avatar
Nahla Shiri committed
261

Nahla Shiri's avatar
Nahla Shiri committed
262
                                <?php if (wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type('variable') )) : ?>
Nahla Shiri's avatar
Nahla Shiri committed
263

Nahla Shiri's avatar
Nahla Shiri committed
264
                                    <span class="sku_wrapper"><span class="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : nap_variable_meta($current_variationID, 'sku'); ?></span></span>
Nahla Shiri's avatar
Nahla Shiri committed
265

Nahla Shiri's avatar
Nahla Shiri committed
266
                                <?php endif; ?>
Nahla Shiri's avatar
Nahla Shiri committed
267 268


Nahla Shiri's avatar
Nahla Shiri committed
269 270 271 272
                                <?php do_action('woocommerce_product_meta_end'); ?>

                            </div>

Nahla Shiri's avatar
Nahla Shiri committed
273 274 275 276
                        </div>
                    </div>
                </div>
                <div class = "btn-list">
Nahla Shiri's avatar
Nahla Shiri committed
277 278
                    <a href="<?php echo get_permalink(157); ?>" class="btn pink-btn rounded">Nous contacter</a>
                    <a class="btn pink-btn rounded download-btn download_file">Télécharger la fiche technique </a>
279
                    <a href="<?php echo get_permalink(43); ?>?product_id=<?php echo $product->get_id()?>&" class="hidden download_file_link" id="<?php echo $current_variationID ?>"></a>
Nahla Shiri's avatar
Nahla Shiri committed
280 281 282 283 284 285 286 287 288 289 290 291 292
                </div>
                <div class="font-small circle-btn add-icon show-product"><span class= "abs-center">Produits associées</span></div>
            </div>
    </div>
    <div class="product-list transition border-l fixed">
        <div class="suggest-header">
            <h2>Produits associés</h2>
            <span class="close-btn"></span>
        </div>
        <div class="product-list-content"> 
            <article class = "row full-width">
                <a href="#"></a>
                <figure>
Nahla Shiri's avatar
Nahla Shiri committed
293
                    <img src="http://nap.mano.fr/wp-content/uploads/2017/07/505714-papier-toilette-jumbo-500x375.jpg" alt="" title="">
Nahla Shiri's avatar
Nahla Shiri committed
294
                </figure>
Nahla Shiri's avatar
Nahla Shiri committed
295
                <h3 class = "font-small" >Bobines papier toilette</h3>
Nahla Shiri's avatar
Nahla Shiri committed
296 297 298 299
            </article>
            <article class = "row full-width">
                <a href="#"></a>
                <figure>
Nahla Shiri's avatar
Nahla Shiri committed
300
                    <img src="http://nap.mano.fr/wp-content/uploads/2017/07/450108-flexibles-noirs-21cm-315x500.jpg" alt="" title="">
Nahla Shiri's avatar
Nahla Shiri committed
301
                </figure>
Nahla Shiri's avatar
Nahla Shiri committed
302
                <h3 class = "font-small" >Pailles</h3>
Nahla Shiri's avatar
Nahla Shiri committed
303
            </article>
Nahla Shiri's avatar
Nahla Shiri committed
304 305
            
            
Nahla Shiri's avatar
Nahla Shiri committed
306 307 308
        </div>
    </div>
</div>