I have the following lines of code in my website that will display the related products at the bottom of my single product page in WooCommerce...
functions.php:
// display upsells and related products within dedicated div with different column and number of products
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
remove_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products',10);
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
function woocommerce_output_related_products() {
$output = null;
ob_start();
woocommerce_related_products(4,4);
$content = ob_get_clean();
if($content) { $output .= $content; }
echo '<div class="clear"></div>' . $output;
}
As it displays 4 products that have been categorized under the same name, how would I modify the above, to display the related tags instead?
For example, I have a product category called 'Automotive' and within this category, are a few tags - 'Holden', 'Ford', 'Toyota', 'Nissan' etc.
I would like it to display 4 products at the bottom, related to the tag of the product the user is currently viewing.