• Resolved tille

    (@tille)


    I think I have tried all options – but I just can not change the number of Related Products in WooCommerce 3.0.4.

    I hoped the most promising snippet would be the one that can be found in the docs: “Change number of related products output

    function woo_related_products_limit() {
      global $product;
    	
    	$args['posts_per_page'] = 6;
    	return $args;
    }
    add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' );
      function jk_related_products_args( $args ) {
    	$args['posts_per_page'] = 4; // 4 related products
    	$args['columns'] = 2; // arranged in 2 columns
    	return $args;
    }

    I put it into the functions.php of my storefront child theme but it just doesn’t have any effect on the number of items displayed. Any pointers / suggestions appreciated. Thank you!

Viewing 1 replies (of 1 total)
  • Thread Starter tille

    (@tille)

    ok – found it: I hooked into the woocommerce_output_related_products_args filter – the priority (99) is important since some other function was probably always setting the number to 3. So now I have this in the functions.php of my storefront child theme:

    add_filter( 'woocommerce_output_related_products_args', 'hff_commerce_child_related_products_args', 99, 3 );
     
      function hff_commerce_child_related_products_args( $args ) {
    	  
    	//  echo("RELATED :::");
        $args = array( 
            'posts_per_page' => 4,  
            'columns' => 4,  
            'orderby' => 'DESC',  
     ); 
     	return $args;
    }

    …and it works… 

Viewing 1 replies (of 1 total)
  • The topic ‘How to change number of Related Products? (WC 3)’ is closed to new replies.