WordPress Tricks

Show custom dropdown based on visited url in woocommerce category page

Suppose in some specific url ( mainly your product category page url) you want to show some specific or customize dropdown. Here I am sharing you such code which you can use by customizing it.

add_action( 'woocommerce_before_shop_loop', 'showcustomdropdown', 31 );
 
function showcustomdropdown() {      
   if ( is_product_category() ) {      
     // wc_product_dropdown_categories();
	$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];


if ((strpos($url,'?product_cat=wall-mounted+single-zone') !== false) || strpos($url,'?product_cat=floor-mounted+single-zone') !== false || strpos($url,'?product_cat=ceilling-cassettes+single-zone') !== false || strpos($url,'?product_cat=concealed-duct+single-zone') !== false || strpos($url,'/mini-split-ac/single-zone/') !== false)  {
	echo "<select id='product_cat'>";
	echo '<option value=" ">'."Select Category"."</option>"; 
   echo '<option value="?product_cat=wall-mounted+single-zone">'. "Wall Mounted" .  '</option>';
	echo '<option value="?product_cat=floor-mounted+single-zone">'."Floor Mounted"  .  '</option>';
	echo '<option value="?product_cat=ceilling-cassettes+single-zone">'. "Ceilling Cassettes" .  '</option>';
	echo '<option value="?product_cat=concealed-duct+single-zone">'. "Concealed Duct" .  '</option>';
	echo "</select>";
} else {
    
}
	   
   } 
   wc_enqueue_js( "
      $('#product_cat').change(function () {
         location.href = '/shop/' + $(this).val();
      });
   " );
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s