Search code examples
phpwordpresswoocommerceproducthook-woocommerce

Change gallery thumbnails count & number of related products in Woocommerce


In Woocommerce I would like to show 3 thumbnails on single product the gallery image slider and also to get displayed 3 related products only.

How to change gallery thumbnails count & number of related products in Woocommerce?

Any help is appreciated.


Solution

  • To get 3 displayed thumbnails in the product image gallery you will use:

    add_filter ( 'woocommerce_product_thumbnails_columns', 'three_product_thumbnails_columns', 10, 1 );
    function three_product_thumbnails_columns( $columns ) {
        return 3; // Default is 4
    }
    

    To get 3 displayed related products:

    add_filter( 'woocommerce_output_related_products_args', 'three_related_products', 10, 1 );
    function three_related_products( $args ) {
        $args['posts_per_page'] = 3;
        $args['columns'] = 3;
        
        return $args;
    }
    

    Both codes goes in function.php file of your active child theme (active theme). Tested and works.