Skip Navigation

[Resolved] Sorting Options for WooCommerce

This support ticket is created 4 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 4 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1863691

We have built a view for a product category (WooCommerce Shop) that works well so far. Filters, sorting, output, all on a good way - although it would have been very helpful to place the sorting independently from the filters - but that's another matter. Now to our concrete request:

The sorting should contain:
1. standard (menu_order)
2. price ascending (field-views_woo_price / ascending)
3. price descending (field-views_woo_price / descending)

Is it possible to realize this sorting in one call ([wpv-sort-orderby])? Or does it always need [wpv-sort-order]? Unfortunately, the latter makes no sense at all with the standard sorting. Also the two dropdowns next to each other are not very user-friendly ...

Do you have an idea for us?

Regards

#1864197

Hello,

Unfortunately, there isn't such kind of built-in feature within Toolset, you can pass only one "wpv_sort_orderby" URL parameter to Views, so it is not possible to sort the result by two fields at the same time.

In your case, you might consider custom codes, for example, use action hook "pre_get_posts" in your shop page:
https://developer.wordpress.org/reference/hooks/pre_get_posts/

And follow WP document to customize the "orderby" parameter of WP_Query:
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

See the example in above document:
https://developer.wordpress.org/reference/hooks/pre_get_posts/#div-comment-2571

#1864385

Hi Luo,

i don't want to sort the result by two fields at the same time. I want a Dropdown with different parameters, and sorting after selection:
1. standard (menu_order)
2. price ascending (field-views_woo_price / ascending)
3. price descending (field-views_woo_price / descending)

So always sort by one parameter, but one ascending, once descending ...

Is there any possibility?

#1865267

Unfortunately, there isn't such kind of built-in feature, as a workaround, you can use custom codes to setup the Dropdown you mentioned above, and pass two URL parameters to views:
- wpv_sort_orderby (Field name)
- wpv_sort_order (Sort order)
- wpv_view_count (This is Toolset WordPress Archive ID)

For example:
hidden link