Related Products do not change
-
On my website, whenever I select a product, I can see some related products on the bottom. I understand that these related products are selected by the WooCommerce default behavior of selecting random products by category. However I am seeing the same related products no matter what product I select. For example, I have about 100 items in my Fall category. No matter what product I chose, I always get the same items in the “Related Products” at the bottom of the page. Isn’t this suppose to be a random selection of products within the category?
-
does anybody know why this is?
I have the same problem, trying to find a solution but can’t seem to find anyone else with the issue. I’ve found that the same products showing are actually the first 4 products I entered into the shop, regardless of what category they are in it only shows those 4 on every product.
Don’t know where our support is on this. Would like it working properly.
The related products that are displayed are selected from a pool of related products. By default though, the pool is the same size as the number to be displayed. The products selected for the pool will be in date-of-creation order, not random order. Those selected may be displayed in random order, but they will be the same products.
So, we need to make the pool bigger. This can be achieved using a hook, and retrieving a bigger pool of products. The code goes in functions.php of your child theme:
<?php add_filter('woocommerce_related_products_args', 'my_related'); function my_related($args) { global $product; $pool_size = 10; $related = $product->get_related($pool_size); if ( sizeof( $related ) == 0 ) return $args; $args["post__in"] = $related; return $args; } // end functionThere doesn’t seem to be a penalty for specifying a pool size bigger than your number of products, though maybe it’ll slow a fraction if you choose a really big number. Some experimentation may be necessary.
Sorry not overly confident about this but above works for me.
One last thing, if you have a cache running, you will see the same products in the same order until the cached page expires and is recreated.
Thankyou Lorro. I assume this code will select all products in the same category as the product selected to the cart. What is the significance of 39 in this code?
get_related() is a WooCommerce function and it selects products in the same category and with the same tag. The limit is set by the variable $pool size.
I can’t see a “39”.
Thats wierd. It must have been a display thing cause it is gone now. I will try implementing this today. Thanks for following up. Wonder why woocommerce hasnt implemented a fix like this into their plugin. We cant be the only ones that have noticed this problem….
Ha. that 39 appears as an ascii code when I see this post in an email…
I am getting an error that says unexpected “<” error.
Here is my file:
<?php
/*
* Generated By Orbisius Child Theme Creator – your favorite plugin for Child Theme creation 🙂
* https://wordpress.org/plugins/orbisius-child-theme-creator/
*
* Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent.
* Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent theme’s functions.php).
* Source: http://codex.wordpress.org/Child_Themes#Using_functions.php
*
* Be sure not to define functions, that already exist in the parent theme!
* A common pattern is to prefix function names with the (child) theme name.
* Also if the parent theme supports pluggable functions you can use function_exists( ‘put_the_function_name_here’ ) checks.
*/
<?php
add_filter(‘woocommerce_related_products_args’, ‘my_related’);
function my_related($args) {
global $product;
$pool_size = 10;
$related = $product->get_related($pool_size);
if ( sizeof( $related ) == 0 ) return $args;
$args[“post__in”] = $related;
return $args;
} // end functionFigured it out. I had 2 <?php statements in there.
Took one out.
Now, when I add just one item to the cart, I only get one item that shows up under the line that says “You may also be interested in these products”.
However, if I add another item into the cart, I get the 3 items that show up. They are different products now, so we are on the right path. How do we get three (3) items to show up if just one item is added to the cart?Further testing revealed that some products do not have anything show up there after I add something to the cart. Such as a print. However if I add a lamp, then I get one more lamp showing up after I go to the cart. Can you shed some light as to why there are not 3 items showing up like it used to?
My website is http://www.goodolddayscountryshop.com
JohnThe cart page has cross-sells not related products. I don’t see why my bit of code should have any effect on cross sells. Did you check that, for the particular product you’re looking at, that you have set up a sufficient number of cross sells in the product data section > linked products tab.
hi, I’ve tried the code and it now produces random products from the amount from my pool, but it still does not take from categories or tags, just random from the first 10 or any other number I add from the pool from the shop. On woocommerce site it says the related products should take from the same category and tags, mine are not
Lorro, thanks for pointing out my confusion here. Just for the record so other readers can understand….
The code suggested here is a work-around in order to get the related products feature of woocommerce to work. The related products show up when one selects a certain product from the store. The related products are related from the same category, or if one uses tags, from the same tags. I do not use tags. When I test this code, it works. I see various related items from the same category appear whenever I select a product from my store.
To differentiate, once an item is added to the cart, the customer is shown other products that they might be interested in. These items are set up by the developer when inputting the product details. Specifically, “linked products” – “Cross-Sells”.
In summary, woocommerce appears to have a flaw in that it shows the same products in the related products area whenever a product is selected. It is suppose to show different products within the same category. This code snippet allows the feature to actually work this way. I have tested it on my site and it works well. Again, I do not use tags at all. using tags might affect how this works. I am not marking this as resolved because woocommerce has not been fixed permanently. This is just a work around.So I add the code into my functions.php, which allows me to create a bigger pool to choose from, but its still completely random and does not sort by category, any suggestions or thoughts?
The topic ‘Related Products do not change’ is closed to new replies.