This code modifies the WooCommerce product shortcode so it only displays products from the same taxonomy term as the single product.
The code also handles multiple taxonomies by excluding out of stock products so only products related to the same taxonomy term, which are “in stock”, are shown. And it also removes the current single product from the list avoiding duplicates.
The code also works with plugins like YITH which generate custom taxonomy terms for brands however you can use the code with tax terms generated by code or any other plugin.
There’s only 1 step :
Copy & paste the PHP code to the end of your child themes functions.php file or custom functionality plugin.
Swap out all 3 instances of
yith_product_brand in the code with the taxonomy slug of your taxonomy.
The code was written to replace the YITH WooCommerce Brands Addon and match existing taxonomy, terms & products used with the plugin.
These solutions may also help :