Based upon this I have tried to write the following code as:
Custom Page template:
/*
Template Name: product_filter
*/
get_header();
do_action( 'pre_get_posts', 'COOLING');
Functions.php
add_action('pre_get_posts','shop_filter_cat',10,1);
function shop_filter_cat($query, $arg) {
if (!is_admin() && is_post_type_archive( 'product' ) && $query->is_main_query()) {
$query->set('tax_query', array(
array ('taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $arg
)
)
);
}
}
But I have got following warning:
Warning: Missing argument 2 for shop_filter_cat(), called in E:\xampp\htdocs\wordpress\wp-includes\plugin.php on line 600 and defined in E:\xampp\htdocs\wordpress\wp-content\themes\storefront\functions.php on line 56
and error:
Fatal error: Uncaught Error: Call to a member function is_main_query() on string in E:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce\includes\wc-deprecated-functions.php:677 Stack trace: #0 E:\xampp\htdocs\wordpress\wp-includes\plugin.php(524): wc_shop_order_status_backwards_compatibility('COOLING') #1 E:\xampp\htdocs\wordpress\wp-content\themes\storefront\testing.php(6): do_action('pre_get_posts', 'COOLING') #2 E:\xampp\htdocs\wordpress\wp-includes\template-loader.php(75): include('E:\xampp\htdocs...') #3 E:\xampp\htdocs\wordpress\wp-blog-header.php(19): require_once('E:\xampp\htdocs...') #4 E:\xampp\htdocs\wordpress\index.php(17): require('E:\xampp\htdocs...') #5 {main} thrown in E:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce\includes\wc-deprecated-functions.php on line 677