Restrict related products on Single Product pages to parent category only
-
Hi,
Right now the related products section is showing randon products from other categories.
How do I get it to show only parent categories?
If I copy over the default woocommerce related.php file it fixes it by showing only directly related products but the styling obviously isn’t the same.
Hello,
Do you mean that default WordPress theme will show different related products than our theme? Actually, related products query is located in WooCommerce core and is not overrided by our theme.
Regards
Really? I copied the related.php file from the woocommerce plugin template folder to replace the file in your theme and it showed me only related products in the same category as the product I view.
Before, your theme was showing me random products from other categories.
Strange, could you please provide us your admin and FTP access so we can check it and fix if there is a bug in the theme?
If you go to the link I sent it shows a AC Milan product and the related are all random.
If I copy the woocommerce version of related.php over to the theme then it shows all AC Milan related.
But we tested with default related.php file and this section always show random products
https://prnt.sc/hrgtbi
https://prnt.sc/hrgsz7
Could you please describe us how do you achieve this result? Or maybe do this temporarily so we can see how it works.
Sorry I sent you the wrong web link before.
I uploaded a custom related.php file to my child theme using the following code:
https://pastebin.com/LKRRSNXV
Since the products have 2 separate categories – brand and product type:
This gym bag is in AC Milan and Gym Bags categories.
This new related.php allows related to only show those products related.
So can you provide us the admin and FTP access to this website so we can check it there?
Yes, it was in a post above.
So you have default related.php now that comes with WooCommere plugin, right? Each time we reload the page we see random related products.