As you know we’ve redesigned the product gallery feature in WooCommerce to deliver a richer experience in 3.0.
This is a significant frontend change that can be broken down in to three separate new features;
- Image zoom / magnification
- Lightbox
- Slider
To enable each of these features in your theme you must declare support using add_theme_support()
like so;
[code language=”php”]
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’ );
}[/code]
This allows you the flexibility to pick and choose exactly which features you want to include/exclude in your theme or at your store.
Styling
If your theme disables WooCommerce core styles you will also need to provide a layout for the new gallery. The classes you’ll want to work with are;
.woocommerce-product-gallery
– The gallery wrapper. This wrapper will also include a class that indicates how many columns thumbnails should be arranged into, e.g..woocommerce-product-gallery--columns-4
.woocommerce-product-gallery__wrapper
– The slider wrapper.woocommerce-product-gallery__image
– Thefigure
that contains the image itself, which is wrapped in an anchor
.woocommerce-product-gallery__trigger
– This is the link that triggers the lightbox functionality.flex-control-thumbs
– If you’re using the slider functionality the Flexslider script creates the thumbnails in aol
with this class
A note on the column class; If you anticipate that your users might want to change the columns using the woocommerce_product_thumbnails_columns
filter, you might also want to include styles for other column layouts besides the default.
If you’re interested you can find the sass we use in Storefront to style the new gallery layout here.
That’s it! Go forth and add support for WooCommerce 3.0’s gallery feature to your themes!
Leave a Reply