Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More →
WooCommerce product loop is generally on shop page and category page. on both pages WooCommerce provide hooks before the loop and after the loop.
For adding a category dropdpwn or other texonomy dropdown We will use "woocommerce_before_shop_loop".
For Both Product loop. (shop page and category page)
function CategorySwitcher() {
wc_product_dropdown_categories();
$category_base=get_option('woocommerce_permalinks')['category_base'];
wc_enqueue_js( "
('#product_cat').change(function () {
location.href = '".site_url().'/'.$category_base."/' + $(this).val();
});
");
}
add_action('woocommerce_before_shop_loop','CategorySwitcher',100);
For Only Category Archive Page.
function CategorySwitcher() {
if ( is_product_category() ) {
wc_product_dropdown_categories();
}
$category_base=get_option('woocommerce_permalinks')['category_base'];
wc_enqueue_js( "
('#product_cat').change(function () {
location.href = '".site_url().'/'.$category_base."/' + $(this).val();
});
");
}
add_action('woocommerce_before_shop_loop','CategorySwitcher',100);
For Only Shop Page.
function CategorySwitcher() {
if ( is_shop() ) {
wc_product_dropdown_categories();
}
$category_base=get_option('woocommerce_permalinks')['category_base'];
wc_enqueue_js( "
('#product_cat').change(function () {
location.href = '".site_url().'/'.$category_base."/' + $(this).val();
});
");
}
add_action('woocommerce_before_shop_loop','CategorySwitcher',100);
Search our archives or reach out to our team for solutions and expert advice.