Slider for product thumbnails in WooCommerce
By default, the WooCommerce FlexSlider plugin handles your main product gallery and a separate list of thumbnails. The core issue arises when you have many images; the thumbnails wrap into multiple rows instead of scrolling horizontally. This happens because the standard initialization lacks specific configuration to treat the thumbnail list as a navigation control rather than a grid.
To fix this, you need to tell FlexSlider that the main gallery should be synchronized with the thumbnail container. The plugin expects two distinct elements: one acting as the slider and another acting as the controls. In your case, the main images are wrapped in .woocommerce-product-gallery__wrapper, while the thumbnails are inside .flex-control-thumbs.
You can configure this behavior without editing template files by using a WordPress filter. This approach keeps your custom theme clean and leverages the existing FlexSlider library already loaded by WooCommerce.
Add the following code to your functions.php file or a custom plugin:
add_filter('woocommerce_single_product_carousel_options', 'ud_update_woo_flexslider_options');
function ud_update_woo_flexslider_options($options) {
$options['directionNav'] = true;
$options['sync'] = '.flex-control-thumbs';
return $options;
}
This filter modifies the global options array for the main gallery. By setting 'sync' to .flex-control-thumbs, you instruct the main slider to look at that specific CSS selector and treat it as its control navigation. This effectively converts the static thumbnail list into a scrollable strip, allowing users to click a thumbnail to jump directly to that image in the main view.
However, there is a critical distinction between how the main gallery and the thumbnails behave. The code above only configures the primary slider (.woocommerce-product-gallery__wrapper). It does not automatically initialize FlexSlider for the thumbnails themselves. If you want the thumbnails to also be swipeable or scrollable horizontally, they require their own initialization logic.
The standard WooCommerce setup often initializes the thumbnails via a different mechanism or leaves them as static images. To make the thumbnail strip itself a functional slider (allowing swiping or arrow navigation within the thumbs), you must explicitly initialize it after the main gallery has finished loading. You can do this using jQuery, targeting the specific classes in your HTML output.
Here is how you would initialize the thumbnail container as a secondary slider:
$(document).ready(function() {
// Initialize the main gallery with synced thumbnails
$('.woocommerce-product-gallery__wrapper').flexslider({
animation: "slide",
controlNav: false,
slideshow: true,
sync: ".flex-control-thumbs"
});
// Initialize the thumbnail strip as a slider
$('.flex-control-thumbs').flexslider({
animation: "slide",
controlNav: false,
animationLoop: true,
slideshow: false,
itemWidth: 210,
itemMargin: 5,
asNavFor: '.woocommerce-product-gallery__wrapper'
});
});
In this example, the first initialization targets the main wrapper and sets sync to point at the thumbnails. The second initialization targets the thumbnail list (.flex-control-thumbs). Notice the use of asNavFor, which tells the thumbnail slider that it is controlling another slider instance. This ensures that clicking a thumbnail not only updates the view but also manages the scroll position of the thumbnail strip itself if desired.
A common pitfall when adapting FlexSlider examples is trying to hardcode IDs or rely on specific HTML structures that differ from the default WooCommerce output. Since WooCommerce generates unique data attributes and classes, you should always target selectors based on those stable class names rather than inline IDs or text content. The filter approach handles the synchronization logic server-side, while the JavaScript block ensures both DOM elements are treated as independent but linked sliders.
If you encounter issues where the thumbnails still wrap or do not sync, verify that the jQuery library is loaded before your script runs. Additionally, ensure that no other scripts are overriding the flexslider initialization. When working with custom themes, keeping your CSS minimal and relying on the plugin's default styles for the slider mechanics usually yields the most predictable results.