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 company he has led since 2009. An AI & IT Solutions Consultant with 16+ years of experience, he works with startups and enterprises to turn ideas into market-ready SaaS platforms, mobile apps and AI-driven solutions. His team has delivered 700+ projects across SaaS, mobile and web apps, automation and AI. He previously served as Chief Technology Officer for a US company.

Latest Posts

Colour photograph illustrating the Eoxys blog post 'Computer-Use AI Agents: Automate Old Software Without an API', used as the featured image for computer use ai agents.

Computer-Use AI Agents: Automate Old Software Without an API

Every business has a task like this: an employee logs into a government portal, a supplier site or a 15-year-old…

Shafeeq Khan
November 16, 2026
Colour photograph illustrating the Eoxys blog post 'Product Feed Optimization for ChatGPT Shopping and AI Mode', used as the featured image for product feed optimization ai shopping.

Product Feed Optimization for ChatGPT Shopping and AI Mode

When a shopper asks ChatGPT or Google AI Mode for “the best running shoes under ₹6,000 for flat feet”, the…

Shafeeq Khan
November 15, 2026
Colour photograph illustrating the Eoxys blog post 'Hire an AI Product Manager: Skills, Salary and When You Need One', used as the featured image for hire ai product manager.

Hire an AI Product Manager: Skills, Salary and When You Need One

Your team can call a model API in an afternoon. Deciding what the AI feature should do, how good is…

Shafeeq Khan
November 14, 2026
,

Leave a Reply

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