Content of the page

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

Content of the article

  • Install this plugin: https://wordpress.org/plugins/widget-logic/other_notes/
  • 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()) {
        $_REQUEST['MDF_IS_WOO_CAT'] = TRUE;
        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: 
    <?php
    
    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;
            do_shortcode('[meta_data_filter_results]');
            $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