WooCommerce : Display a Product Category Dropdown and Redirect To Single Category Upon Selection.

Code

How To add category dropdown Before WooCommerce product loop?

WooCommerce product loop is generally on shop page and category page. on both pages WooCommerce provide hooks before the loop and after the loop.

  1. “woocommerce_before_shop_loop”
  2. “woocommerce_after_shop_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);

null

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);

null

Related reading:

Shiv Kumawat

Executive Director & CEO

Shiv Kumawat is the CEO of Eoxys IT Solution LLP, the Jaipur-based IT and GenAI development company he has led since 2009. Eoxys builds custom AI, web and mobile applications for businesses worldwide. Shiv writes about AI app development, generative AI for business, and building software products that deliver real results. Connect with him on LinkedIn: https://www.linkedin.com/in/shiv-kumawat-eoxys/

Latest Posts

Isometric illustration of an online store connected to three AI shopping agents handling product discovery, chat and checkout

AI Shopping Agents for E-commerce: Get Your Store Ready Now

This is the first holiday season where AI shopping agents are a real sales channel. Shopify’s 2026 holiday research, published…

Shiv Kumawat
October 7, 2026
Build vs buy AI hiring software: custom-built blocks versus a ready-made hiring dashboard, balanced by AI

Build vs Buy AI Hiring Software: A 2026 Decision Guide

Recruiting is where most companies meet AI first. In SHRM’s 2025 Talent Trends research, 51% of organizations said they use…

Shiv Kumawat
October 6, 2026
On-device AI in mobile apps: models running locally on the phone

On-Device AI Mobile Apps in 2026: Benefits, Trade-offs and Use Cases

  On-device AI means the model runs on the user’s phone instead of on your servers. Since September 2025, every…

Shafeeq Khan
February 18, 2026
,

Leave a Reply

Your email address will not be published. Required fields are marked *