Layered nav support on unsupported theme archives

This commit is contained in:
claudiulodro 2018-03-01 11:28:00 -08:00
parent 3e114799ca
commit 383317c256
1 changed files with 22 additions and 0 deletions

View File

@ -275,7 +275,9 @@ class WC_Template_Loader {
$prefix = '';
}
add_filter( 'woocommerce_shortcode_products_query', array( __CLASS__, 'unsupported_archive_layered_nav_compatibility' ) );
$shortcode = new WC_Shortcode_Products( $shortcode_args );
remove_filter( 'woocommerce_shortcode_products_query', array( __CLASS__, 'unsupported_archive_layered_nav_compatibility' ) );
$shop_page = get_post( self::$shop_page_id );
$dummy_post_properties = array(
@ -328,6 +330,26 @@ class WC_Template_Loader {
add_filter( 'template_include', array( __CLASS__, 'force_single_template_filter' ) );
}
/**
* Add layered nav args to WP_Query args generated by the 'products' shortcode.
*
* @since 3.3.4
* @param array $query WP_Query args.
* @return array
*/
public static function unsupported_archive_layered_nav_compatibility( $query ) {
foreach ( WC()->query->get_layered_nav_chosen_attributes() as $taxonomy => $data ) {
$query['tax_query'][] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $data['terms'],
'operator' => 'and' === $data['query_type'] ? 'AND' : 'IN',
'include_children' => false,
);
}
return $query;
}
/**
* Force the loading of one of the single templates instead of whatever template was about to be loaded.
*