How do I set colour swatches, per-term images, or colours programmatically?
Published
For a colour swatch, add the widget, choose the colour attribute, choose the Colour (or “Colour col2”) display type and Save – a colour selector then appears next to each option. For a custom image per term, set a Thumbnail under Products > Attributes > [attribute] > Edit Terms. If you have thousands of colours mapped in a file, set the hex programmatically with our filter (note we use the American spelling color):
add_filter('ssf_change_color_hex', 'override_ssf_color_hex', 10, 3);
function override_ssf_color_hex($colorhex, $term_id, $taxonomy) {
// change your colours here based on term_id and taxonomy
return $colourhex;
}
You get the hex you set in our interface (empty if unset), plus the $term_id and $taxonomy (e.g. pa_color). For a split “multicolour” swatch, give the term a unique hex and target it with a CSS gradient.
Still stuck? Post a screenshot on our Discord.
Further reading
every other known problem and its fix.
setting up and configuring the filters.
Comments