There is a filter hook to change the orderby paramater for the output of the upsell products. That filter can be seen in code here: https://github.com/woocommerce/woocommerce/blob/3.7.0/includes/wc-template-functions.php#L1958
Thread Starter
doyuk
(@doyuk)
I changed the order with this hook:
function custom_upsell_display() {
woocommerce_upsell_display( -1, 4, 'menu_order', 'asc' );
}
But “Products> Sorting” is not the same as sorting.
https://monosnap.com/file/BzqCIxXROyGSrhYqdSeDhSMbU7Rql5
https://monosnap.com/file/PCkZ2zQiiykf6qwgk8kLDOS8GhDFan
https://doyuk.com.tr/product/wooden-usb-memory-stick/
slash1andy
(@slash1andy)
Automattic Happiness Engineer
Hey there!
Since this is a few weeks old, and about customization, I am going to mark as resolved. A lot of people have found help in the Advanced WooCommerce group with things like this, so I would recommend checking there, or we highly recommend contacting one of the services on our Customizations page (https://woocommerce.com/customizations/)
Hey @doyuk
It’s been a while but if you ever need more control over the sort order of upsells and cross-sells, you could have a look at the Product Recommendations extension, which allows you to build custom recommendation engines and sort the results by popularity (week, month, quarter, all time), rating, creation date and even conversion rate.
The extension is probably overkill for what you want to achieve here, but I thought I’d chime in as I noticed you are using product recommendations quite a lot on your site 🙂
Thread Starter
doyuk
(@doyuk)
Hi,
This code worked for me. But it is listed as “DESC”. How can I rank as “ASC”?
function filter_woocommerce_upsells_orderby( $orderby ) {
return ‘menu_order’;
};
add_filter( ‘woocommerce_upsells_orderby’, ‘filter_woocommerce_upsells_orderby’, 10, 1 );
Thread Starter
doyuk
(@doyuk)
Shared solutions did not work.
I found a hook and it worked.
function filter_woocommerce_upsells_orderby( $orderby ) {
return 'menu_order';
};
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
But DESC – is in reverse order.
I want to rank it as ASC.
https://doyuk.com/?s=SQUARE&post_type=product
https://monosnap.com/file/ghV7d5jzztkh09lpY0fahdUXXmCw3R
https://doyuk.com/usb-memory-sticks/square-shaped-card-usb-memory-stick/
https://monosnap.com/file/CuFScIuuiYooDGkEpEvxulVypqowEn
Hey Doyuk,
I also had this issue & fixed it with following code:
/* SORT UPSELLS IN ASCENDING ORDER */
/* --- */
// ORDER BY
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
function filter_woocommerce_upsells_orderby( $orderby ) {
return 'menu_order';
};
// ORDER
add_filter( 'woocommerce_upsells_order', 'filter_upsells_order', 10, 1 );
function filter_cross_sells_order( $order ){
return 'asc'; // Default is 'desc'
}
So you were almost there :). I added the woocommerce_upsells_order to specify the ascending order.
Take care!
-
This reply was modified 6 years, 5 months ago by
Petasos. Reason: Change order of code to make it more logic
Thread Starter
doyuk
(@doyuk)
Dear Petasos,
Thank you for your support.
The code works flawlessly.
Best regards