Trying to display related products in WooCommerce by categories only. At present WooCommerce uses tags and categories.
We've tried implementing the following, but I'm guessing over time this will have stopped working perhaps owing to updates on WooCommerce side. It now no longer works in any theme we've tested.
add_filter( 'woocommerce_product_related_posts_relate_by_tag', '__return_false' );
A functional alternative:
Looking at the related core code at line 842 you have this:
You will notice a second filter hook:
woocommerce_get_related_product_tag_terms
. So may be you can try to use instead this code:Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This is tested and works.