[contact-form-7 id="24078" title="Feedback EN"]

Featured templates

WooCommerce. How to change the number of related products

This tutorial is going to show you how to change the number of related products in WooCommerce.

WooCommerce. How to change the number of related products

You already know how to set up related products. We will show you how to change number of related products in this tutorial.

WooCommerce._How_to_change_the_quantity_of_related_products

Please, follow steps below to change related products number:

  1. Connect to your server using FTP or hosting Cpanel.

  2. Locate file called shop-functions.php in wp-content/themes/theme#####/includes folder (where ##### is your theme number).

  3. Modify lines 80-97:

    //Related products limit
    function tm_related_products_limit() {
    	global $product;
        $orderby = '';
    	$columns = 4;
    	$related = $product->get_related( 4 );
    	$args = array(
    		'post_type'           => 'product',
    		'no_found_rows'       => 1,
    		'posts_per_page'      => 4,
    		'ignore_sticky_posts' => 1,
    		'orderby'             => $orderby,
    		'post__in'            => $related,
    		'post__not_in'        => array($product->id)
    	);
    	return $args;
    }
    add_filter( 'woocommerce_related_products_args', 'tm_related_products_limit' );
  4. Change $related = $product->get_related( 4 ); number to the number of related products you would like to be shown on your site.

    On the same lines you can change number of columns and order by settings.

Feel free to check the detailed video tutorial below:

WooCommerce. How to change the number of related products