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.

WooCommerce: Change Number of Related Products
WooCommerce: Change Number of Related Products WooCommerce: Change Number of Related Products

Snippet (PHP): Change Number of Related Products (Rows & Cols) – WooCommerce


/**
 * @snippet       WooCommerce Change Number of Related Products
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=17473
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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%;
}
}

Share:

Leave a Reply