variable.php 16.2 KB
Newer Older
imac's avatar
imac committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
/**
 * 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
18 19
if (!defined('ABSPATH')) {
    exit;
imac's avatar
imac committed
20 21 22
}

global $product;
23
$ambiance_product = $product->get_gallery_attachment_ids();
imac's avatar
imac committed
24

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

27
$parent_cat = wp_get_post_terms($product->get_id(), 'product_cat', array( 'parent' => 0,'fields' => 'ids' ));
28
$sub_cat = wp_get_post_terms($product->get_id(), 'product_cat', array( 'parent' =>$parent_cat[0],'fields' => 'all' ));
Nahla Shiri's avatar
Nahla Shiri committed
29
$current_variationID = $_GET['variation_id'];
30
$ext_ref = externe_referrer();
31 32
$class_back = "";
$category_link = get_category_link($parent_cat[0]);
33
if($ext_ref) {
34
    $class_back = "ext-link";
35
}
Nahla Shiri's avatar
Nahla Shiri committed
36 37
if (!function_exists('print_attribute_radio')) {

38 39
    function print_attribute_radio($checked_value, $value, $label, $name, $index=0) {
       
Nahla Shiri's avatar
Nahla Shiri committed
40
        $current_color = $_GET['attribute_couleur'];
41 42
        $selected = $default_checked = "";
        if ($value == strtolower($current_color)){
Nahla Shiri's avatar
Nahla Shiri committed
43
            $default_checked = "checked";
44 45 46
            $selected = "selected";
        }
           
Nahla Shiri's avatar
Nahla Shiri committed
47
        $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
48

Nahla Shiri's avatar
Nahla Shiri committed
49 50 51 52 53 54 55 56 57
        $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 . '; }
58 59
                    </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
60 61
        } else {
            $icons = nap_icon_format($value);
62 63 64 65
            
                $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
66
            $filtered_label = apply_filters('woocommerce_variation_option_name', $label);
Nahla Shiri's avatar
Nahla Shiri committed
67
            printf('<li class="format-list selected"><input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s checked>
68

69
                <label class="format-label" for="%3$s">'.$format_img.'</label>
70
                <div class="format-desc">'.$label.'</span>
71
                </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
72 73 74
        }
    }

75
}   
Nahla Shiri's avatar
Nahla Shiri committed
76 77 78

do_action('woocommerce_before_add_to_cart_form');
?>
Nahla Shiri's avatar
Nahla Shiri committed
79 80

<div id="product" class="clearfix">
Nahla Shiri's avatar
Nahla Shiri committed
81
    <div class="product-images row animated">
82
        <div class = "btn-wrapper row close-panel <?php echo $class_back ?>">
83
            <div class="pink-btn circle-btn"><a href="<?php echo $category_link ?>"><span class = "abs-center backlink">Retour</span></a></div>
Nahla Shiri's avatar
Nahla Shiri committed
84
        </div>
85
        <div class="product-slides row">
Nahla Shiri's avatar
Nahla Shiri committed
86
            <div class="product-header">
87
                <h2 class="crete -italic font-small"><?php echo $sub_cat[0]->name; ?></h2>
88
                <h3 class="crete"><?php the_title();?></h3>
Nahla Shiri's avatar
Nahla Shiri committed
89
            </div>
imac's avatar
imac committed
90
            <span class="close-btn display--only-mobile"></span>
91 92 93 94 95 96 97 98 99 100
            <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
101
                        <?php
102 103 104
                        $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
105
                            ?>
106 107 108
                            <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
109 110 111 112
                                </a>
                            </div>

                            <?php
113
                        endforeach;
Nahla Shiri's avatar
Nahla Shiri committed
114 115
                        
                         if (!empty($ambiance_product)) {
116 117 118 119
                                $ambiance = $ambiance_product;
                            } else {
                                $ambiance = array();
                            }
Nahla Shiri's avatar
Nahla Shiri committed
120 121
                        if (get_field('images_ambiance', 'product_cat_' . $sub_cat[0]->term_id)):
                            
122
                            while (has_sub_field('images_ambiance', 'product_cat_' . $sub_cat[0]->term_id)) :
123 124 125 126 127
                                $image_amb = get_sub_field('img_ab');
                                $ambiance [] = $image_amb;

                            endwhile;
                        endif;
128 129 130 131 132 133 134 135
                        foreach ($ambiance as $key => $value) :
                            $attachment = wp_get_attachment_image_src($value, 'medium');
                            $hd = wp_get_attachment_image_src($value, 'full');
                            ?>
                            <div  style="background-image:url('<?php echo $attachment[0]; ?>')" class="image element-slider  easyzoom easyzoom--overlay easyzoom--with-toggle" data-color = "<?php echo $value; ?>" data-slick-index = "1">
                                <a href="<?php echo $hd[0]; ?>"> </a>
                            </div>
                        <?php endforeach; ?>
Nahla Shiri's avatar
Nahla Shiri committed
136

137 138
                    </div>  
                </div>
Nahla Shiri's avatar
Nahla Shiri committed
139 140 141 142 143 144 145 146 147 148 149 150 151
                <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;
152 153 154 155 156
                        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
157

158
                                <article class = "row" data-color = "<?php echo $value; ?>">
159 160 161 162 163 164 165 166 167
                                    <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
168 169


Nahla Shiri's avatar
Nahla Shiri committed
170 171
                    </div>
                </div>
Nahla Shiri's avatar
Nahla Shiri committed
172 173
            </div> 
        </div>
Nahla Shiri's avatar
Nahla Shiri committed
174 175 176
    </div>


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

Nahla Shiri's avatar
Nahla Shiri committed
179
        <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
180 181 182 183 184 185
            <?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
186 187 188 189
                        
                    <?php 
                    $i=0;
                    foreach ($attributes as $name => $options) : ?>
190
                        <div class="list row <?php echo $name;?> left border-l center">
Nahla Shiri's avatar
Nahla Shiri committed
191 192

                            <div class="product-header center font-small label">
193
                                <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
194 195 196 197 198 199 200 201 202 203 204
                            </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 = '';
                            }
                            ?>
imac's avatar
imac committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
                            <div class="list-wrapper">
                                <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'));

                                            foreach ($terms as $key=>$term) {
                                                if (!in_array($term->slug, $options)) {
                                                    continue;
                                                }
                                                print_attribute_radio($checked_value, $term->slug, $term->name, $sanitized_name,$key);
                                                
                                            }
                                        } else {
                                            foreach ($options as $option) {
                                                print_attribute_radio($checked_value, $option, $option, $sanitized_name);
                                               
Nahla Shiri's avatar
Nahla Shiri committed
224 225 226 227
                                            }
                                        }
                                    }

imac's avatar
imac committed
228 229 230 231
                                    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
232
                        </div>
Nahla Shiri's avatar
Nahla Shiri committed
233
                    <?php $i++;endforeach; ?>
Nahla Shiri's avatar
Nahla Shiri committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251

                </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
252 253
        </form>
        <div class="product-info row center left border-l">
Nahla Shiri's avatar
Nahla Shiri committed
254
                <div class="info-content">
Nahla Shiri's avatar
Nahla Shiri committed
255

256
                    <h2 class = "crete  font-small" ><?php echo $sub_cat[0]->name; ?></h2>
257
                    <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
258
                    <div class="details font-small">
Nahla Shiri's avatar
Nahla Shiri committed
259 260
                        <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
261 262
                    </div>
                    <div class="price">
Nahla Shiri's avatar
Nahla Shiri committed
263
                        <span class="crete"><?php echo nap_variable_meta($current_variationID, 'price'); ?> € ht</span>
Nahla Shiri's avatar
Nahla Shiri committed
264 265 266
                        <div class="notice">( prix public conseillé )</div>
                        <div class="font-small">
                            <div class="product_meta">
imac's avatar
imac committed
267

Nahla Shiri's avatar
Nahla Shiri committed
268
                                <?php do_action('woocommerce_product_meta_start'); ?>
Nahla Shiri's avatar
Nahla Shiri committed
269

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

Nahla Shiri's avatar
Nahla Shiri committed
272
                                    <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
273

Nahla Shiri's avatar
Nahla Shiri committed
274
                                <?php endif; ?>
Nahla Shiri's avatar
Nahla Shiri committed
275 276


Nahla Shiri's avatar
Nahla Shiri committed
277 278 279 280
                                <?php do_action('woocommerce_product_meta_end'); ?>

                            </div>

Nahla Shiri's avatar
Nahla Shiri committed
281 282 283 284
                        </div>
                    </div>
                </div>
                <div class = "btn-list">
Nahla Shiri's avatar
Nahla Shiri committed
285 286
                    <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>
287
                    <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
288 289 290 291 292 293 294 295 296 297 298 299 300
                </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
301
                    <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
302
                </figure>
Nahla Shiri's avatar
Nahla Shiri committed
303
                <h3 class = "font-small" >Bobines papier toilette</h3>
Nahla Shiri's avatar
Nahla Shiri committed
304 305 306 307
            </article>
            <article class = "row full-width">
                <a href="#"></a>
                <figure>
Nahla Shiri's avatar
Nahla Shiri committed
308
                    <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
309
                </figure>
Nahla Shiri's avatar
Nahla Shiri committed
310
                <h3 class = "font-small" >Pailles</h3>
Nahla Shiri's avatar
Nahla Shiri committed
311
            </article>
Nahla Shiri's avatar
Nahla Shiri committed
312 313
            
            
Nahla Shiri's avatar
Nahla Shiri committed
314 315
        </div>
    </div>
imac's avatar
imac committed
316
    <div class="display--only-mobile"><span class = "chevron bottom blue-bg down-btn show-product-mobile"></span></div>
Nahla Shiri's avatar
Nahla Shiri committed
317
</div>