variable.php 15.7 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
$parent_cat = wp_get_post_terms($product->get_id(), 'product_cat', array( 'parent' => 0,'fields' => 'ids' ));
$sub_cat = wp_get_post_terms($product->get_id(), 'product_cat', array( 'parent' =>$parent_cat[0],'fields' => 'names' ));
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);
67
            printf('<li class="format-list selected"><input type="radio" name="%1$s" value="%2$s" id="%3$s" %4$s>
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]; ?></h2>
88
                <h3 class="crete"><?php the_title();?></h3>
Nahla Shiri's avatar
Nahla Shiri committed
89
            </div>
90 91 92 93 94 95 96 97 98 99
            <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
100
                        <?php
101 102 103
                        $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
104
                            ?>
105 106 107
                            <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
108 109 110 111
                                </a>
                            </div>

                            <?php
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
                        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
134

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

156 157 158 159 160 161 162 163 164 165
                                <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
166 167


Nahla Shiri's avatar
Nahla Shiri committed
168 169
                    </div>
                </div>
Nahla Shiri's avatar
Nahla Shiri committed
170 171
            </div> 
        </div>
Nahla Shiri's avatar
Nahla Shiri committed
172 173 174
    </div>


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

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

                            <div class="product-header center font-small label">
191
                                <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
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
                            </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'));

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

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

                </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
248 249
        </form>
        <div class="product-info row center left border-l">
Nahla Shiri's avatar
Nahla Shiri committed
250
                <div class="info-content">
Nahla Shiri's avatar
Nahla Shiri committed
251

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

Nahla Shiri's avatar
Nahla Shiri committed
264
                                <?php do_action('woocommerce_product_meta_start'); ?>
Nahla Shiri's avatar
Nahla Shiri committed
265

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

Nahla Shiri's avatar
Nahla Shiri committed
268
                                    <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
269

Nahla Shiri's avatar
Nahla Shiri committed
270
                                <?php endif; ?>
Nahla Shiri's avatar
Nahla Shiri committed
271 272


Nahla Shiri's avatar
Nahla Shiri committed
273 274 275 276
                                <?php do_action('woocommerce_product_meta_end'); ?>

                            </div>

Nahla Shiri's avatar
Nahla Shiri committed
277 278 279 280
                        </div>
                    </div>
                </div>
                <div class = "btn-list">
Nahla Shiri's avatar
Nahla Shiri committed
281 282
                    <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>
283
                    <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
284 285 286 287 288 289 290 291 292 293 294 295 296
                </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
297
                    <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
298
                </figure>
Nahla Shiri's avatar
Nahla Shiri committed
299
                <h3 class = "font-small" >Bobines papier toilette</h3>
Nahla Shiri's avatar
Nahla Shiri committed
300 301 302 303
            </article>
            <article class = "row full-width">
                <a href="#"></a>
                <figure>
Nahla Shiri's avatar
Nahla Shiri committed
304
                    <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
305
                </figure>
Nahla Shiri's avatar
Nahla Shiri committed
306
                <h3 class = "font-small" >Pailles</h3>
Nahla Shiri's avatar
Nahla Shiri committed
307
            </article>
Nahla Shiri's avatar
Nahla Shiri committed
308 309
            
            
Nahla Shiri's avatar
Nahla Shiri committed
310 311 312
        </div>
    </div>
</div>