• Resolved mbasfour

    (@mbasfour)


    I am trying to make the WooCommerce shop page display 3 products per row in the main loop only not in any other products widgets on the shop page, I want those widgets to show 4 products per row

    I am using the following filter to do so

    add_filter(
    	'loop_shop_columns', 
    	function( $columns ) {
    		return is_shop() ? 3 : 4;
    	},
    	10,
    	1
    );

    What is happening is that since is_shop returns true if it’s the shop page the main shop loop and all widgets on the shop page are being affected and showing 3 products per row instead of 4, I need a way to check if the current loop is the main shop loop to change the number of columns to be 3 or 4 otherwise

Viewing 5 replies - 1 through 5 (of 5 total)
  • Saif

    (@babylon1999)

    Hi there,

    From what I understand, you want ONLY the shop page to be capped at three products per page.

    If that’s the case, please replace your code with the snippet below. ??

    // Change the Number of WooCommerce Products Displayed Per Page
    add_filter( 'loop_shop_per_page', 'lw_loop_shop_per_page', 30 );
    
    function lw_loop_shop_per_page( $products ) {
     $products = 3;
     return $products;
    }

    I tested it on my site and the widgets were not affected. ??

    You can also change this from the theme settings from WooCommerce > Product catalogue settings.

    Screenshot: https://i.imgur.com/wHqfL9E.png

    If you’d like to read more about this, you can check the following guide: https://woocommerce.com/document/woocommerce-customizer/#product-catalog

    Cheers!

    Thread Starter mbasfour

    (@mbasfour)

    @babylon1999 thank you for your answer, but this is not what I want to implement, I want to change the number of columns, not the number of products to show on the shop page.

    Hello,

    What is happening is that since is_shop returns true if it’s the shop page the main shop loop and all widgets on the shop page are being affected and showing 3 products per row instead of 4,

    Can you please provide a link to your shop page so that we can take a closer look?

    Thanks.

    Thread Starter mbasfour

    (@mbasfour)

    Hi @ihereira
    This is the shop page https://accessories.domvp.xyz/shop/
    You can see that the Recently Viewed widget products are 4 same as the shop, when I use the above code this widget will also show 3 products per row, I want the main loop only to be 3 products per row and everything else to be 4

    Mirko P.

    (@rainfallnixfig)

    Hi @mbasfour,

    Thanks for sharing your site’s URL.

    This forum is intended to provide support for the default version of the WooCommerce core plugin, and guidance on developing extended functionalities falls outside our scope of support.

    I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out, and in the meantime, I can recommend you these links for resources and questions on custom coding:

    – WooCommerce Developer Resources Portal https://developer.woocommerce.com/
    – WooCommerce Slack Community https://woocommerce.com/community-slack/
    – Advanced WooCommerce group on Facebook https://www.facebook.com/groups/advanced.woocommerce/

    If you need any assistance with the code and/or customization, you can also reach out to a web developer or one of our experts.

    Kind regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise’ is closed to new replies.