Skip to main content
This guide shows you how to transform variant option pills (like “Red”, “Blue”, “Green”) into visual image swatches using variant images.
Before starting, you need to assign images to your variants. See the Variant Images documentation for setup instructions.

How it works

The code below intercepts the surecart/product-variant-pill block and replaces the text pill with a thumbnail from the variant’s assigned image. When a customer clicks a swatch, the product image updates to show the selected variant.

Implementation

Add this code to your theme’s functions.php file or a custom plugin.

Customization options

Change the variant option name

By default, this code targets the “color” variant option. To use a different option (like “Size” or “Material”), change the variable at the top:

Show variant labels

To display the variant name below each swatch, uncomment the label section in the code:

Adjust swatch size

Modify the width and height values in the style attribute to change the swatch dimensions:

Styling the swatches

Add CSS to customize the selected and disabled states:

Product Hooks

Additional hooks for customizing product display.

Checkout Customization

Add custom fields and content to checkout.