Commit 7cb2e887 authored by Nahla Shiri's avatar Nahla Shiri

function.php

parent 344636f1
...@@ -57,7 +57,6 @@ jQuery(document).ready(function() { ...@@ -57,7 +57,6 @@ jQuery(document).ready(function() {
jQuery('article').removeClass('hidden'); jQuery('article').removeClass('hidden');
//filtre couleur
var tabcolor = []; var tabcolor = [];
i = 0; i = 0;
jQuery("#pa_couleur .selected").each(function() { jQuery("#pa_couleur .selected").each(function() {
...@@ -75,10 +74,18 @@ jQuery(document).ready(function() { ...@@ -75,10 +74,18 @@ jQuery(document).ready(function() {
jQuery("#pa_matiere .selected").each(function() { jQuery("#pa_matiere .selected").each(function() {
tabmatiere[i++] = jQuery(this).text(); tabmatiere[i++] = jQuery(this).text();
}); });
var tabunivers = [];
i = 0;
jQuery("#pa_univers .selected").each(function() {
tabunivers[i++] = jQuery(this).text();
});
var selected_colors = tabcolor.join(','); var selected_colors = tabcolor.join(',');
var selected_formats = tabformat.join(','); var selected_formats = tabformat.join(',');
var selected_matiere = tabmatiere.join(','); var selected_matiere = tabmatiere.join(',');
var params = {pa_couleur: selected_colors, pa_format: selected_formats, pa_matiere: selected_matiere}; var selected_univers = tabunivers.join(',');
var params = {pa_couleur: selected_colors, pa_format: selected_formats, pa_matiere: selected_matiere, pa_univers:selected_univers};
window.location.href = "?" + jQuery.param(params); window.location.href = "?" + jQuery.param(params);
/*history.pushState({}, null, "?" + jQuery.param(params)); /*history.pushState({}, null, "?" + jQuery.param(params));
......
...@@ -726,3 +726,20 @@ function nap_trash_fiche_technique($post_id) { ...@@ -726,3 +726,20 @@ function nap_trash_fiche_technique($post_id) {
$wpdb->delete($table, array('meta_key' => 'fiche_simple_auto', 'meta_value' => $post->post_title)); $wpdb->delete($table, array('meta_key' => 'fiche_simple_auto', 'meta_value' => $post->post_title));
$wpdb->delete($table, array('meta_key' => 'fiche_var_auto', 'meta_value' => $post->post_title)); $wpdb->delete($table, array('meta_key' => 'fiche_var_auto', 'meta_value' => $post->post_title));
} }
add_action( 'pre_get_posts', 'nap_change_filter_post' );
function nap_change_filter_post() {
global $wp_query;
if(is_admin()) {
if(!empty($wp_query->query_vars['product_cat'])) {
setcookie("product_cat", $wp_query->query_vars['product_cat']);
}
if(!isset($_GET['product_cat']) && ($_GET['post_type'] == 'product')) {
$wp_query->query_vars['product_cat'] = $_COOKIE['product_cat'];
}
elseif(isset($_GET['product_cat']) && empty($_GET['product_cat'])) {
setcookie("product_cat", $wp_query->query_vars['product_cat']);
}
}
}
...@@ -70,31 +70,26 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -70,31 +70,26 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
?> ?>
<div class="bloc-content"> <div class="bloc-content">
<ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?> id="<?php echo $value; ?>"> <ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?> id="<?php echo $value; ?>">
<?php <?php
$colors = array(); $colors = array();
foreach ($terms as $term) : foreach ($terms as $term) :
if ($value == 'pa_couleur'): if ($value == 'pa_couleur'):
$colors[$term->name] = get_field('couleurs', 'pa_couleur_' . $term->term_id); $colors[$term->name] = get_field('couleurs', 'pa_couleur_' . $term->term_id);
/* if (isset($color) && strlen($color) > 0): else :
$filter_class = nap_selected_filter($_GET['pa_couleur'],$color); $filter_format = nap_selected_filter($_GET['pa_format'], $term);
?> $filter_matiere = nap_selected_filter($_GET['pa_matiere'], $term);
<li data-color = "<?php echo $color; ?>" class="<?php echo $term->name.' '.$filter_class; ?>"></li> $filter_univers = nap_selected_filter($_GET['pa_univers'], $term);
<?php ?>
endif; */
else : <li class="<?php echo $filter_format . ' ' . $filter_matiere .' '.$filter_univers ; ?>"><?php echo $term; ?></li>
$filter_format = nap_selected_filter($_GET['pa_format'], $term); <?php
$filter_matiere = nap_selected_filter($_GET['pa_matiere'], $term); endif;
?> endforeach;
foreach (array_unique($colors) as $name => $code) {
<li class="<?php echo $filter_format . ' ' . $filter_matiere; ?>"><?php echo $term; ?></li> if (isset($code) && strlen($code) > 0):
<?php $filter_class = nap_selected_filter($_GET['pa_couleur'], $code);
endif; ?>
endforeach;
foreach (array_unique($colors) as $name => $code) {
if (isset($code) && strlen($code) > 0):
$filter_class = nap_selected_filter($_GET['pa_couleur'], $code);
?>
<li data-color = "<?php echo $code; ?>" class="<?php echo $name . ' ' . $filter_class; ?>"></li> <li data-color = "<?php echo $code; ?>" class="<?php echo $name . ' ' . $filter_class; ?>"></li>
<?php <?php
endif; endif;
...@@ -103,13 +98,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -103,13 +98,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
?> ?>
<li class="reinit">Tout déselectionner</li> <li class="reinit">Tout déselectionner</li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
...@@ -120,7 +115,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -120,7 +115,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div> </div>
</div> </div>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php <?php
foreach ($child_category as $key => $value) : foreach ($child_category as $key => $value) :
?> ?>
...@@ -129,13 +124,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of' ...@@ -129,13 +124,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
<p><?php echo $value->description; ?></p> <p><?php echo $value->description; ?></p>
</div> </div>
</div> </div>
<?php <?php
endforeach; endforeach;
?> ?>
</div> </div>
<div class="right-panel right"> <div class="right-panel right">
<div class="panel panel-content list-animation"> <div class="panel panel-content list-animation">
<?php if ($_GET['pa_couleur'] != '' || $_GET['pa_format'] != '' || $_GET['pa_matiere'] != ''): ?> <?php if ($_GET['pa_couleur'] != '' || $_GET['pa_format'] != '' || $_GET['pa_matiere'] != ''): ?>
<span class="search_result">Résultat de votre recherche :</span> <span class="search_result">Résultat de votre recherche :</span>
<?php endif; ?> <?php endif; ?>
...@@ -149,33 +144,29 @@ endforeach; ...@@ -149,33 +144,29 @@ endforeach;
</div> </div>
</div> </div>
<div class="product-list"> <div class="product-list">
<?php <?php
$args = array('post_type' => 'product', 'stock' => 1, 'posts_per_page' => -1, 'product_cat' => $value->name, 'orderby' => 'title', 'order' => 'ASC'); $args = array('post_type' => 'product', 'stock' => 1, 'posts_per_page' => -1, 'product_cat' => $value->name, 'orderby' => 'title', 'order' => 'ASC');
$naps_posts = new WP_Query($args); $naps_posts = new WP_Query($args);
$options = array(); $options = array();
while ($naps_posts->have_posts()) : $naps_posts->the_post(); while ($naps_posts->have_posts()) : $naps_posts->the_post();
$id = get_the_ID(); $id = get_the_ID();
$list_att = array(); $list_att = array();
$options['size'] = (get_field('produit_affichage', $id)) ? get_field('produit_affichage', $id) : 'small'; $options['size'] = (get_field('produit_affichage', $id)) ? get_field('produit_affichage', $id) : 'small';
$args = array( $args = array(
'post_type' => array('product', 'product_variation'), 'post_type' => array('product', 'product_variation'),
'post_status' => array('private', 'publish'), 'post_status' => array('private', 'publish'),
'numberposts' => -1, 'numberposts' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'asc', 'order' => 'asc',
'post_parent' => $id 'post_parent' => $id
); );
?>
<?php
/* * ************* */
$attribute_value['pa_couleur'] = get_the_terms($id, 'pa_couleur'); $attribute_value['pa_couleur'] = get_the_terms($id, 'pa_couleur');
$attribute_value['pa_format'] = get_the_terms($id, 'pa_format'); $attribute_value['pa_format'] = get_the_terms($id, 'pa_format');
$attribute_value['pa_matiere'] = get_the_terms($id, 'pa_matiere'); $attribute_value['pa_matiere'] = get_the_terms($id, 'pa_matiere');
$attribute_value['pa_univers'] = get_the_terms($id, 'pa_univers'); $attribute_value['pa_univers'] = get_the_terms($id, 'pa_univers');
if ($_GET) { if ($_GET) {
if (is_array($attribute_value['pa_couleur'])) { if (is_array($attribute_value['pa_couleur'])) {
foreach ($attribute_value['pa_couleur'] as $key => $value) { foreach ($attribute_value['pa_couleur'] as $key => $value) {
...@@ -197,7 +188,7 @@ endforeach; ...@@ -197,7 +188,7 @@ endforeach;
$list_att['pa_univers'] = $value->name; $list_att['pa_univers'] = $value->name;
} }
} }
nap_filter_attribute($id, $args, $options, $list_att, $_GET); nap_filter_attribute($id, $args, $options, $list_att, $_GET);
} else { } else {
echo nap_get_item($id, $args, $current_page, $options); echo nap_get_item($id, $args, $current_page, $options);
} }
...@@ -206,9 +197,9 @@ endforeach; ...@@ -206,9 +197,9 @@ endforeach;
?> ?>
</div> </div>
</section> </section>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<?php get_footer(); ?> <?php get_footer(); ?>
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment