This code displays 3 related product loops on every single product page.
- If the single product is out of stock, Loop 1 displays related products by category before the product.
- Regardless of stock status, Loop 2 displays related products by category.
- Regardless of stock status, Loop 3 displays related products by brand.
The download includes code to create a custom taxonomy named brands.
- Only instock products are included.
- Products in all loops are unique as all product ids on the single product page are checked and duplicates are removed.
- The code enables you to display x number of products based on how many products are included in each taxonomy or term.
There’s only 1 step. Copy & paste the PHP code to the end of your child themes functions file or custom functionality plugin and remember to clear caching & re-save permalinks.
Note : If your installation already includes code or a plugin which creates a custom taxonomy for brands, only copy of the code from line 45 of functions.php and swap out the value for the taxonomy parameter on line 260 & 380 from brands with the name ( slug ) of your taxonomy.