Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add product sorting dropdown in WooCommerce?

I saw a lot of questions on stackoverflow about removing this dropdown. I want to ADD IT on my theme and it doesn't work.

I tried adding this:

add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );

aaand didn't work.

What's the catch? I already have in my archive-product.php this piece of code:

<?php
 /**
 * woocommerce_before_shop_loop hook
 *
 * @hooked woocommerce_result_count - 20
 * @hooked woocommerce_catalog_ordering - 30
 */
 do_action( 'woocommerce_before_shop_loop' );
?>

So the sorting template is included, right? Where am I messing this up?

like image 841
Punct Ulica Avatar asked Sep 05 '25 03:09

Punct Ulica


2 Answers

First add this to your functions.

<?php 
 // sorting
 remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
 add_action( 'woo_custom_catalog_ordering', 'woocommerce_catalog_ordering', 30 ); 
?>

Then wherever you want to have the sort box just drop it in.

<?php do_action( 'woo_custom_catalog_ordering' ); ?>
like image 117
Frithir.com Avatar answered Sep 07 '25 17:09

Frithir.com


Found the solution thanks to Anand. the .woocommerce-ordering class had a display:none on it.

like image 33
Punct Ulica Avatar answered Sep 07 '25 15:09

Punct Ulica