This code shows products related to the single product firstly by tag then category otherwise products by brand are shown.
Related products :
- Are shown on Out of Stock single products page only.
- Are in stock meaning no Out of Stock products are shown.
- Free from duplicates meaning no related product will display twice.
- Are only shown if there’s 4 or more related products in the same taxonomy.
There’s only 1 step.
Add the code to the end of your child themes functions file or custom functionality plugin and remember to clear caching & WooCommerce transients.
Note : The file includes code to add a custom taxonomy named brand. If you already have code which creates brands, only copy the code starting from line 47.
There’s also code on line 45 to remove the default WooCommerce related products loop.