Nicola Mustone

Support Lead @ Automattic


Leadership, web, programming. Short essays and hands-on guides, focused on results, not hype.


Reordering Cross-Sells and Up-Sells in WooCommerce

1–2 minutes
Order Cross Sells and Up Sells

Cross-sells and Up-sells in WooCommerce are a very powerful tool to give suggestions to your customers.

You might know that most people who buy product X will probably need product Y as well, and you want the customer to know that. How do you do it? You use cross-sells and up-sells.

These products are shown respectively on the product page and on the cart page. They show like they would show on the Shop page in most cases. The only difference would be their order.

By default, cross-sells and up-sells are randomly sorted. But what if you want to change that? Maybe you want to show them by publish date, or by ID. As usual, there are filters for it!

Before you make any code changes, have a backup of your site. This will help you restore things in case of unforeseen errors. I recommend using Jetpack Backup for real-time backups and one-click restores.

You can add this code to your functions.php file in wp-content/themes/your-child-theme-name/:

// Up-sells sorting
add_filter( 'woocommerce_upsells_orderby', function() { return 'date'; } );
add_filter( 'woocommerce_upsells_order', function() { return 'desc'; } );

// Cross-sells sorting
add_filter( 'woocommerce_cross_sells_orderby', function() { return 'date'; } );
add_filter( 'woocommerce_cross_sells_order', function() { return 'desc'; } );

You can refer to the WP_Query documentation for more values available for orderby. Find more documentation about cross-sells and up-sells on WooCommerce.com.

Cite This Essay

Use this ready-formatted reference in your work or research notes.


One response to “Reordering Cross-Sells and Up-Sells in WooCommerce”

  1. Client wants to order upsells by a custom order – not by date or ID, but by the product sort order as set on the Admin products page. Any hint as to how to do that?

    Thanks!

Leave a Comment

Discover more from Nicola Mustone

Subscribe now to keep reading and get access to the full archive.

Continue reading