query changes
This commit is contained in:
parent
369fad9eab
commit
91f459b71b
|
@ -51,7 +51,7 @@ class WooCommerce_Widget_Layered_Nav extends WP_Widget {
|
|||
$terms = get_terms( $taxonomy, $args );
|
||||
$count = count($terms);
|
||||
if($count > 0){
|
||||
|
||||
|
||||
$found = false;
|
||||
ob_start();
|
||||
|
||||
|
@ -59,14 +59,21 @@ class WooCommerce_Widget_Layered_Nav extends WP_Widget {
|
|||
|
||||
echo "<ul>";
|
||||
|
||||
// Force found when option is selected
|
||||
if (array_key_exists($taxonomy, $_chosen_attributes)) $found = true;
|
||||
|
||||
foreach ($terms as $term) {
|
||||
|
||||
$_products_in_term = get_objects_in_term( $term->term_id, $taxonomy );
|
||||
|
||||
$count = sizeof(array_intersect($_products_in_term, $woocommerce_query['filtered_product_ids']));
|
||||
|
||||
|
||||
if ($count>0) $found = true;
|
||||
|
||||
$option_is_set = (isset($_chosen_attributes[$taxonomy]) && in_array($term->term_id, $_chosen_attributes[$taxonomy]));
|
||||
|
||||
if ($count==0 && !$option_is_set) continue;
|
||||
|
||||
$class = '';
|
||||
|
||||
$arg = 'filter_'.strtolower(sanitize_title($instance['attribute']));
|
||||
|
@ -120,11 +127,11 @@ class WooCommerce_Widget_Layered_Nav extends WP_Widget {
|
|||
|
||||
echo '<li '.$class.'>';
|
||||
|
||||
if ($count>0) echo '<a href="'.$link.'">'; else echo '<span>';
|
||||
if ($count>0 || $option_is_set) echo '<a href="'.$link.'">'; else echo '<span>';
|
||||
|
||||
echo $term->name;
|
||||
|
||||
if ($count>0) echo '</a>'; else echo '</span>';
|
||||
if ($count>0 || $option_is_set) echo '</a>'; else echo '</span>';
|
||||
|
||||
echo ' <small class="count">'.$count.'</small></li>';
|
||||
|
||||
|
|
|
@ -83,9 +83,9 @@ class WooCommerce_Widget_Price_Filter extends WP_Widget {
|
|||
FROM $wpdb->posts
|
||||
LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id
|
||||
WHERE meta_key = 'price' AND (
|
||||
$wpdb->posts.ID IN (".implode(',', $woocommerce_query['unfiltered_product_ids']).")
|
||||
$wpdb->posts.ID IN (".implode(',', $woocommerce_query['layered_nav_product_ids']).")
|
||||
OR (
|
||||
$wpdb->posts.post_parent IN (".implode(',', $woocommerce_query['unfiltered_product_ids']).")
|
||||
$wpdb->posts.post_parent IN (".implode(',', $woocommerce_query['layered_nav_product_ids']).")
|
||||
AND $wpdb->posts.post_parent != 0
|
||||
)
|
||||
)"));
|
||||
|
|
|
@ -15,33 +15,8 @@ $woocommerce_query['unfiltered_product_ids'] = array(); // Unfilted product ids
|
|||
$woocommerce_query['filtered_product_ids'] = array(); // Filted product ids (after layered nav)
|
||||
$woocommerce_query['post__in'] = array(); // Product id's that match the layered nav + price filter
|
||||
$woocommerce_query['meta_query'] = ''; // The meta query for the page
|
||||
|
||||
/**
|
||||
* Front page archive/shop template
|
||||
*/
|
||||
if (!function_exists('woocommerce_front_page_archive')) {
|
||||
function woocommerce_front_page_archive() {
|
||||
|
||||
global $paged;
|
||||
|
||||
if ( is_front_page() && is_page( get_option('woocommerce_shop_page_id') )) :
|
||||
|
||||
if ( get_query_var('paged') ) {
|
||||
$paged = get_query_var('paged');
|
||||
} else if ( get_query_var('page') ) {
|
||||
$paged = get_query_var('page');
|
||||
} else {
|
||||
$paged = 1;
|
||||
}
|
||||
|
||||
query_posts( array( 'page_id' => '', 'post_type' => 'product', 'paged' => $paged ) );
|
||||
|
||||
define('SHOP_IS_ON_FRONT', true);
|
||||
|
||||
endif;
|
||||
}
|
||||
}
|
||||
add_action('wp', 'woocommerce_front_page_archive', 1);
|
||||
$woocommerce_query['layered_nav_post__in'] = array(); // posts matching layered nav only
|
||||
$woocommerce_query['layered_nav_product_ids'] = array(); // Stores posts matching layered nav, so price filter can find max price in view
|
||||
|
||||
/**
|
||||
* Query the products, applying sorting/ordering etc. This applies to the main wordpress loop
|
||||
|
@ -138,12 +113,22 @@ function woocommerce_get_products_in_view() {
|
|||
)
|
||||
);
|
||||
|
||||
// Add posts to array
|
||||
foreach ($products as $p) $woocommerce_query['unfiltered_product_ids'][] = $p->ID;
|
||||
|
||||
if (sizeof($woocommerce_query['post__in'])>0)
|
||||
// Also store filtered posts ids...
|
||||
if (sizeof($woocommerce_query['post__in'])>0) :
|
||||
$woocommerce_query['filtered_product_ids'] = array_intersect($woocommerce_query['unfiltered_product_ids'], $woocommerce_query['post__in']);
|
||||
else
|
||||
else :
|
||||
$woocommerce_query['filtered_product_ids'] = $woocommerce_query['unfiltered_product_ids'];
|
||||
endif;
|
||||
|
||||
// And filtered post ids which just take layered nav into consideration (to find max price in the price widget)
|
||||
if (sizeof($woocommerce_query['layered_nav_post__in'])>0) :
|
||||
$woocommerce_query['layered_nav_product_ids'] = array_intersect($woocommerce_query['unfiltered_product_ids'], $woocommerce_query['layered_nav_post__in']);
|
||||
else :
|
||||
$woocommerce_query['layered_nav_product_ids'] = $woocommerce_query['unfiltered_product_ids'];
|
||||
endif;
|
||||
}
|
||||
|
||||
|
||||
|
@ -154,6 +139,8 @@ function woocommerce_layered_nav_init() {
|
|||
|
||||
global $_chosen_attributes, $wpdb;
|
||||
|
||||
$_chosen_attributes = array();
|
||||
|
||||
$attribute_taxonomies = woocommerce::$attribute_taxonomies;
|
||||
if ( $attribute_taxonomies ) :
|
||||
foreach ($attribute_taxonomies as $tax) :
|
||||
|
@ -177,7 +164,7 @@ add_filter('loop-shop-posts-in', 'woocommerce_layered_nav_query');
|
|||
|
||||
function woocommerce_layered_nav_query( $filtered_posts ) {
|
||||
|
||||
global $_chosen_attributes, $wpdb;
|
||||
global $_chosen_attributes, $wpdb, $woocommerce_query;
|
||||
|
||||
if (sizeof($_chosen_attributes)>0) :
|
||||
|
||||
|
@ -203,6 +190,9 @@ function woocommerce_layered_nav_query( $filtered_posts ) {
|
|||
|
||||
if ($filtered) :
|
||||
|
||||
$woocommerce_query['layered_nav_post__in'] = $matched_products;
|
||||
$woocommerce_query['layered_nav_post__in'][] = 0;
|
||||
|
||||
if (sizeof($filtered_posts)==0) :
|
||||
$filtered_posts = $matched_products;
|
||||
$filtered_posts[] = 0;
|
||||
|
@ -262,10 +252,8 @@ function woocommerce_price_filter( $filtered_posts ) {
|
|||
$grouped_products = get_objects_in_term( get_term_by('slug', 'grouped', 'product_type')->term_id, 'product_type' );
|
||||
|
||||
if ($grouped_products) foreach ($grouped_products as $grouped_product) :
|
||||
|
||||
$children = get_children( 'post_parent='.$grouped_product.'&post_type=product' );
|
||||
|
||||
if ($children) foreach ($children as $product) :
|
||||
|
||||
if ($children = get_children( 'post_parent='.$grouped_product.'&post_type=product' )) foreach ($children as $product) :
|
||||
$price = get_post_meta( $product->ID, 'price', true);
|
||||
|
||||
if ($price<=$_GET['max_price'] && $price>=$_GET['min_price']) :
|
||||
|
|
|
@ -109,6 +109,35 @@ function woocommerce_get_template_file_url($template_name, $ssl = false) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Front page archive/shop template
|
||||
*/
|
||||
if (!function_exists('woocommerce_front_page_archive')) {
|
||||
function woocommerce_front_page_archive() {
|
||||
|
||||
global $paged;
|
||||
|
||||
if ( is_front_page() && is_page( get_option('woocommerce_shop_page_id') )) :
|
||||
|
||||
if ( get_query_var('paged') ) {
|
||||
$paged = get_query_var('paged');
|
||||
} else if ( get_query_var('page') ) {
|
||||
$paged = get_query_var('page');
|
||||
} else {
|
||||
$paged = 1;
|
||||
}
|
||||
|
||||
query_posts( array( 'page_id' => '', 'post_type' => 'product', 'paged' => $paged ) );
|
||||
|
||||
define('SHOP_IS_ON_FRONT', true);
|
||||
|
||||
endif;
|
||||
}
|
||||
}
|
||||
add_action('wp', 'woocommerce_front_page_archive', 1);
|
||||
|
||||
|
||||
/**
|
||||
* Add Body classes based on page/template
|
||||
**/
|
||||
|
|
Loading…
Reference in New Issue