Website Consultancy and Free Advice

WooCommerce Images & Gallery Snippets & Hooks

Product Images

Image Support for wooCommerce 3.0

wooCommerce 3.0 comes with a new image gallery with zoom and slider. The majority of themes do not have support for this update, so please add the below code to your theme functions.php.
Instructions: Add to your Theme functions.php file


/* Image support for 3.0 */
add_action( 'after_setup_theme', 'yourtheme_setup' );

function yourtheme_setup() {
    add_theme_support( 'wc-product-gallery-zoom' );
    add_theme_support( 'wc-product-gallery-lightbox' );
    add_theme_support( 'wc-product-gallery-slider' );
}

Set number of thumbnail columns in product galleries

You might want to restrict the amount of thumbnails show on the single product gallery. The below code does just that, set the return value to how many you want to show.
Instructions: Add to your Theme functions.php file


add_filter ( 'woocommerce_product_thumbnails_columns', 'custom_thumb_cols' );
 function custom_thumb_cols() {
     return 4; // .last class applied to every 4th thumbnail
 }