This PHP code enables you to use any meta query parameters to control exactly which upsell products are displayed per single product page.
By default, WooCommerce only allows you to filter the value for 4 parameters,
This code gives you the power to control all
orderby parameters as well as all custom field parameters including but not limited to :
‘meta_value‘ ‘meta_value_num‘ ‘meta_key‘ 'meta_compare' 'meta_query'
In this example, upsells are ordered by a number added to the single product page screen for each product rather then the order in which they are added on the Linked Products > Upsells meta box.
If no meta data is found for the meta query you use in the code, the default upsell products are displayed using the default method.
The code also gives you full customization of your upsells products on top of custom meta query parameters without interfering with the default upsells functionality.
There’s 2 simple steps :
1. Copy and paste the PHP code to the end of your child themes functions.php file or custom functionality plugin.
2. Upload the woocommerce folder to your child theme folder.
You can then add data to any single product like this :