Skip Navigation

[Resolved] Order by SKU (Woocommerce and Views)

This support ticket is created 7 years, 7 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.

Our next available supporter will start replying to tickets in about 2.33 hours from now. Thank you for your understanding.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by xavierC-2 7 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#430791

Hi,

I use Views and Woocommerce to display products in a list.

I would like to order the results by SKU, but it's hidden field, so I don't find it in the drop down box on my View.

I checked this page on the forum : https://toolset.com/forums/topic/sorting-by-custom-field/
The solution is from 2014 and I tried it :

function order_by_sku_func($query, $view_settings) {
    if($view_settings['view_id']!= 129) return $query;
    $query['orderby'] = 'meta_value_num';
    $query['order'] = 'ASC';
    $query['meta_query'][] = array(
           'key' => '_sku',
           'value' => 0,
           'compare' => '>',
    );
    return $query;
}
add_filter('wpv_filter_query', 'order_by_sku_func', 10, 2);

I add this to my functions.php, but it seems it doesn't work : I don't see any new field to choose in the Ordering drop down box.

Can you please help me to solve that issue ?

Thank you.

#430900

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Xavier,

Thank you for contacting our support forum.

With our views plugin you should be able to enable these hidden fields to be used. To do this go to Toolset -> Settings -> Frontend-Content -> Hidden Custom fields and click "Select custom field" once you have done this search for _sku and enable it.

After doing that then the sku should show up in the sorting options for your view.

Please let me know if this helps.

Thanks,
Shane

#431312

Thanks Shane, it works ! 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.