No ways to sort Woocommerce product by menu_order meta

So currently when the query is set to use ‘Products’, then under the ‘Order’ tab, there is no way for us to set Order By to either WooCommerce’s menu_order meta (the WooCommerce sorting), or a way for us to enter the meta key for this ‘menu_order’. If I use dynamic data, select sorce to WordPress → Custom field, then enter the meta key ‘menu_order’, it makes no affect of the query in terms of the orders.

Then if I use a function filter from Cwicly and try to use the meta field ‘menu_order’ from WooCommerce, it returns no products at all as my Query is using Frontend rendering.

Here is the code I tried:
add_filter(‘cwicly/query/args’, function ($query_args, $attributes, $id) {
// Modify the query arguments for your specific Query block
if ($id === ‘query-c2a5cb6’) {
$query_args[‘orderby’] = array(
‘meta_value_num’ => ‘ASC’, // Order by host-time custom field
);
$query_args[‘meta_key’] = ‘menu_order’; // Meta key for host-time custom field
}

return $query_args;

}, 10, 3);

So, is there any way to fix this or a way to workaround to make the Order sorting to work based on the default WooCommerce’s order_menu meta?

Environment info

  • WordPress version: 6.3.1
  • Cwicly Plugin version: 1.3

Bump this, so no one build ecommerce website with WooCommerce anymore?

Just highlighting this issue as it hasn’t had much activity yet.

@Araminta, We have a couple of upcoming sites that will need this so I am also eager to make sure it is all working correctly. :raised_hand:

Hi @lukelee,

Apologies for the delayed response.

Indeed, we don’t currently offer the ability to order by menu_order from the Query editor.
Rest assured, we’ll add this as soon as possible.

For the time being, you can get this working with this code snippet:

add_filter('cwicly/query/args', function ($query_args, $attributes, $id) {
    // Modify the query arguments for your specific Query block
    if ($id === 'query-ca4ad03') {
        $query_args['orderby']  = 'menu_order';
    }

    return $query_args; // Always return the modified query arguments
}, 10, 3);

Note: be sure to modify the Query ID to your query’s specific ID.

Hope this helps!

All is working correctly!

If you do notice anything unusual, please don’t hesitate to let us know.

Well, its been almost a month so i came up with my own solution, which is to write a function and create a custom field, and run the function with cronjob to copy whatever the menu_order’s valuevto my custom field, and then use order by in query taccording to my custom field.

I don’t know why but i think WooCommerce should get more attention from Cwicly team. I personally coded a lot of custom function to make Cwicly to work with WooCommerce, but overall the integration and the way it is is already in a very good start, shouldn’t be left out as it is.

Hello there,

This has been addressed in 1.3.4.

The code snippet @lukelee provided in his first post is incorrect, which explains why it didn’t work.
The Cwicly query filter cannot be blamed for improper use.

I will also add that menu_order does not appear as a valid value for the orderby parameter in the WooCommerce documentation for product queries.

Cheers,