Here’s a simple snippet to change the display of Related Products on the single product page. Lately, I even added a fix for the Storefront theme, which already overrides the WooCommerce filter and needs a different call.

Snippet (PHP): Change Number of Related Products (Rows & Cols) – WooCommerce
/** * @snippet WooCommerce Change Number of Related Products * @how-to businessbloomer.com/woocommerce-customization * @sourcecode https://businessbloomer.com/?p=17473 * @author Rodolfo Melogli, Business Bloomer * @compatible WooCommerce 3.5.4 * @community https://businessbloomer.com/club/ */ add_filter( 'woocommerce_output_related_products_args', 'bbloomer_change_number_related_products', 9999 ); function bbloomer_change_number_related_products( $args ) { $args['posts_per_page'] = 4; // # of related products $args['columns'] = 4; // # of columns per row return $args; }
Additional CSS for Storefront Theme – Change Number of Related Products to 4
@media (min-width: 768px) { .site-main .related.products ul.products li.product { width: 22%; float: left; margin-right: 4%; } }
The code still works, but I used flex for css.
Cool
Fantastic – thank you! That’s one less plugin I need to install π
Yay!
I need to do this with a conditional like:
but it doesn’t work, Any suggestions?
Thanks in advance!
I have it, the conditional must be inside the function like this:
In case it serves to someone π
Nice!
How can I display 6 products in single row? It is showing 4+2 in 2 rows
Hello Paul, thanks for your comment. If you entered “6” inside the snippet, then it’s your theme’s fault if that’s the result. You’ll need to add custom CSS to make the output show on 6 columns. Hope this helps
Does this works on the cross sell on the cart page??
Nope, sorry
With WP core 5,1, woocommece 3.5.6 and storefront theme 2.4.3 the number of products shown are fix to 2. The CSS part works fine making room for more, but only two products are shown (from left). I have also Pootlepress Storefront Pro installed.
Works for me π If you disable temporarily all plugins does it work?
Today – feb 6th 2019 – the setting for the number of related items works, however, the column setting does not.
Just #fyi
Hey Han, thanks for your comment! Snippet works for me, so you must have a plugin/theme conflict π
Hello,
Nice work Rodolfo congratulations. I would like to ask if it’s possible to have random related products from the same category and subcategory by using ‘orderby’ => ‘rand’, that kind of argument.
Thank you in advance,
Nikos
Hello Nikos, thanks for your comment π “Orderby” = “rand” is already the default argument, check woocommerce_output_related_products(). so, it should already work like that π
Hello Rodolfo,
Of course it is working like that by default. What it doesn’t do as it should or better as we want to do is showing related products from the same subcategory and not from the parent category.
Thank you in advance,
Nikos
Ah, gotcha! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Thank you SO much, man! You just saved my day π
All the best to you!
Jelena
Brilliant π
How do I change the no.of items per row for Up Sells and Cross sells please.
Hello Geetha, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Wow, Jesse! Thank you very much for this!
Since yesterday I am trying to get more than the usual 3 images to be displayed. Lot of testing with frustrating results. I didn’t expect Storefront to be the cause. If Google would’ve paid me for each single search I did the last days, I would be rich by now. π Luckily I decided to search for storefront specifically.
Thank you again, all the best to you,
-BjΓΆrn
Hi does this still work? Also, does it change the number of upsell products displayed from 3 to 4? I’m running the Divi theme.
Thanks
Hey Lee! Try adding a “9999” priority to the filter so it loads last (I revised the snippet). On top of that, your theme might require additional CSS to manage the WooCommerce columns (see Storefront example). Finally, this only changes the related products, for the upsells the code would be different. Hope this helps!
Thumbs up! StoreFront snippet works like a charm!
Thanks Martin!
I have spent hours looking for a fix. I was trying to display 6 related products in 2 rows of 3 but it wouldn’t display with 3 per row. I would get 2 on one row and then 1 or 2 on the second row depending on how many characters there were in the excerpt. Your Related Products code has fixed this problem instantly. Thank you so much!
Awesome π
Hi,
one more time, amazing – including adaptation for storefront.
Question: any idea how to make the related products displayed only stock products ?
on my shop it shows almost only sold out products…
Thanks a lot π
Ben, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R
Hey, any idea how to change the number of related products in StoreVilla theme ?
Thanks in advance!
No idea Weber π Have you asked your theme developers?
Just FYI, it looks like your Storefront version is exactly the same as your other version except for the function name. I believe you’ll have to give the filter a priority of at least 11 to have it work.
Jesse, spot on! Thanks so much for your comment, I must have forgotten the priority for some obscure reason π Have a great day!