Show Related Products If More than X Number Else Show Different Loop – WooCommerce

$75.00

This code creates 3 custom related product loops displayed before & after single products based on several conditions & checks :

  • Related products are only shown before the single product if its out of stock.
  • If there’s more than 5 products by the same category as the single product, these products will be displayed otherwise products from the 3rd loop are shown by related brand.
  • If the product is in stock, related products are only shown after the single product in loop 2 by same category and loop 3 by brand.
  • All loops display unique in stock products therefore no duplicates are shown.

The download also includes code to create a custom taxonomy named brand.

Installation

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 59 of functions.php and swap out the value for the taxonomy parameter on line 292 from brand with the name ( slug ) of your taxonomy.