Content of the page

How to filter products on the current woocommerce products category page using ‘self’

Content of the article

  • Install this plugin:
  • Create widget specially for filtering on product category page and set this options on this widget: 
  • In your main MDTF widget set 'Widget Logic' condition as: !isset($_REQUEST['MDF_IS_WOO_CAT'])
  • In your special MDTF widget for categories set condition: isset($_REQUEST['MDF_IS_WOO_CAT']) mdtf-tutorial-73
  • Open in your current WordPress theme archive-product.php file drop next code as on screen: 
    if (is_product_taxonomy()) {
        global $wp_query;
        $cat = $wp_query->get_queried_object();
        $additional_tax_query_array = array();
        $additional_tax_query_array[] = array(
            'taxonomy' => $cat->taxonomy,
            'field' => 'term_id',
            'terms' => array($cat->term_id)
        $_REQUEST['MDF_ADDITIONAL_TAXONOMIES'] = $additional_tax_query_array;
  • In the same archive-product.php file drop next code as on screen: 
    if (is_product_taxonomy()) {
        if (class_exists('MetaDataFilter') AND MetaDataFilter::is_page_mdf_data()) {
            $_REQUEST['mdf_do_not_render_shortcode_tpl'] = true;
            $_REQUEST['mdf_get_query_args_only'] = true;
            $args = $_REQUEST['meta_data_filter_args'];
            global $wp_query;
            $wp_query = new WP_Query($args);
            $_REQUEST['meta_data_filter_found_posts'] = $wp_query->found_posts;
  • Note: this example doesn work in ajax mode
  •  Look the demo of this example