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!
You can add this code to your functions.php file in wp-content/themes/your-child-theme-name/:
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.