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

function.php

parent 344636f1
......@@ -57,7 +57,6 @@ jQuery(document).ready(function() {
jQuery('article').removeClass('hidden');
//filtre couleur
var tabcolor = [];
i = 0;
jQuery("#pa_couleur .selected").each(function() {
......@@ -75,10 +74,18 @@ jQuery(document).ready(function() {
jQuery("#pa_matiere .selected").each(function() {
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_formats = tabformat.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);
/*history.pushState({}, null, "?" + jQuery.param(params));
......
......@@ -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_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'
?>
<div class="bloc-content">
<ul <?php if ($value == 'pa_couleur') echo 'class = "list-color-filter clearfix"'; ?> id="<?php echo $value; ?>">
<?php
$colors = array();
foreach ($terms as $term) :
if ($value == 'pa_couleur'):
$colors[$term->name] = get_field('couleurs', 'pa_couleur_' . $term->term_id);
/* if (isset($color) && strlen($color) > 0):
$filter_class = nap_selected_filter($_GET['pa_couleur'],$color);
?>
<li data-color = "<?php echo $color; ?>" class="<?php echo $term->name.' '.$filter_class; ?>"></li>
<?php
endif; */
else :
$filter_format = nap_selected_filter($_GET['pa_format'], $term);
$filter_matiere = nap_selected_filter($_GET['pa_matiere'], $term);
?>
<li class="<?php echo $filter_format . ' ' . $filter_matiere; ?>"><?php echo $term; ?></li>
<?php
endif;
endforeach;
foreach (array_unique($colors) as $name => $code) {
if (isset($code) && strlen($code) > 0):
$filter_class = nap_selected_filter($_GET['pa_couleur'], $code);
?>
<?php
$colors = array();
foreach ($terms as $term) :
if ($value == 'pa_couleur'):
$colors[$term->name] = get_field('couleurs', 'pa_couleur_' . $term->term_id);
else :
$filter_format = nap_selected_filter($_GET['pa_format'], $term);
$filter_matiere = nap_selected_filter($_GET['pa_matiere'], $term);
$filter_univers = nap_selected_filter($_GET['pa_univers'], $term);
?>
<li class="<?php echo $filter_format . ' ' . $filter_matiere .' '.$filter_univers ; ?>"><?php echo $term; ?></li>
<?php
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>
<?php
endif;
......@@ -103,13 +98,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
?>
<li class="reinit">Tout déselectionner</li>
<?php endif; ?>
<?php endif; ?>
</ul>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
......@@ -120,7 +115,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<?php
foreach ($child_category as $key => $value) :
?>
......@@ -129,13 +124,13 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
<p><?php echo $value->description; ?></p>
</div>
</div>
<?php
endforeach;
?>
<?php
endforeach;
?>
</div>
<div class="right-panel right">
<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>
<?php endif; ?>
......@@ -149,33 +144,29 @@ endforeach;
</div>
</div>
<div class="product-list">
<?php
$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);
$options = array();
while ($naps_posts->have_posts()) : $naps_posts->the_post();
$id = get_the_ID();
$list_att = array();
$options['size'] = (get_field('produit_affichage', $id)) ? get_field('produit_affichage', $id) : 'small';
$args = array(
'post_type' => array('product', 'product_variation'),
'post_status' => array('private', 'publish'),
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'asc',
'post_parent' => $id
);
?>
<?php
/* * ************* */
<?php
$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);
$options = array();
while ($naps_posts->have_posts()) : $naps_posts->the_post();
$id = get_the_ID();
$list_att = array();
$options['size'] = (get_field('produit_affichage', $id)) ? get_field('produit_affichage', $id) : 'small';
$args = array(
'post_type' => array('product', 'product_variation'),
'post_status' => array('private', 'publish'),
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'asc',
'post_parent' => $id
);
$attribute_value['pa_couleur'] = get_the_terms($id, 'pa_couleur');
$attribute_value['pa_format'] = get_the_terms($id, 'pa_format');
$attribute_value['pa_matiere'] = get_the_terms($id, 'pa_matiere');
$attribute_value['pa_univers'] = get_the_terms($id, 'pa_univers');
if ($_GET) {
if (is_array($attribute_value['pa_couleur'])) {
foreach ($attribute_value['pa_couleur'] as $key => $value) {
......@@ -197,7 +188,7 @@ endforeach;
$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 {
echo nap_get_item($id, $args, $current_page, $options);
}
......@@ -206,9 +197,9 @@ endforeach;
?>
</div>
</section>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
\ No newline at end of file
<?php get_footer(); ?>
\ 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