How to Change the Number of Related Products in WooCommerce

How to Change the Number of Related Products in WooCommerce
On this page
  1. Why Adjust the Related Products Count
  2. Step 1: Set the Related Products Count and Columns
  3. Troubleshooting
  4. Frequently Asked Questions
  5. Conclusion

You can change the number of related products in WooCommerce by filtering the related products query arguments to set both how many display and how many columns they’re arranged in, without editing any template files.

  • The default count and column layout may not match your theme’s product card width
  • You want fewer, more curated related product suggestions instead of a full row
  • You’re standardizing the related products grid to match your shop page’s column count
PHP
/**
 * Show 4 related products in a 4-column row on the product page
 * Add to your child theme's functions.php
 */
add_filter( 'woocommerce_output_related_products_args', 'set_related_products_count_and_columns', 9999 );

function set_related_products_count_and_columns( $args ) {
    $args['posts_per_page'] = 4;
    $args['columns'] = 4;
    return $args;
}

Variant: Add Matching CSS for the Storefront Theme

Storefront applies its own width calculations for related product columns, so a small CSS adjustment is usually needed alongside the PHP change.

CSS
@media (min-width: 768px) {
    .site-main .related.products ul.products li.product {
        width: 22%;
        float: left;
        margin-right: 4%;
    }
}
Change the number of related products in WooCommerce: the page before adding the code
Before
Change the number of related products in WooCommerce: the page after adding the code
After

Troubleshooting

The Count Changes But the Layout Still Looks Like the Old Column Count

The columns argument controls the PHP-side grid class, but many themes apply their own CSS widths independently. Add a CSS override like the Storefront example above, adjusted to match your own theme’s grid classes.

Related Products Section Disappears Entirely

This usually means the current product doesn’t have enough related products (products sharing the same category or tag) to display anything. Check the product’s category assignments, or lower posts_per_page to a smaller number if inventory is limited.

Frequently Asked Questions

Can I set a different related products count per product category?

Yes, check the current product’s category inside the function with has_term() and return different posts_per_page values conditionally.

Does this affect upsells too?

No, upsells are a manually curated list controlled separately in the product’s Linked Products tab — this filter only affects the automatically generated related products section.

Will increasing the count slow down the product page?

A modest increase (like from 4 to 6 or 8) has negligible impact for most stores, though very large increases on high-traffic pages are worth testing for load time.

Conclusion

A single filter lets you change the number of related products in WooCommerce and control how many columns they display in, though many themes also need a small CSS tweak to match the new layout visually. Test on both desktop and mobile after adjusting, since column widths can behave differently across breakpoints.

See also How to Hide Related Products on the Single Product Page in WooCommerce.

Prefer no code? All-in-One Utilities Woo Add-on handles this kind of change from a settings screen. Its Reviews and related products guide also shows how.

Leave a Reply

Schedule a call