Chiseiko Essential Swatches
Customizing Swatches
The settings screens cover the most common changes: swatch shape, size, layout, and alignment. When you need something the settings do not offer, you can restyle swatches with a few lines of CSS, and developers can change their markup with PHP filters.
Everything in this chapter works with the free plugin on its own and with Pro. Every example here is checked by the plugin's automated tests, so you can copy it as written.
Where to Put Custom CSS
Add CSS where your theme keeps it, never inside the plugin's own files (plugin updates replace those files).
- Classic themes (such as Storefront or Astra): go to Appearance → Customize → Additional CSS, paste the CSS, and click Publish.
- Block themes (such as Twenty Twenty-Five): go to Appearance → Editor → Styles, open the Styles menu, and choose Additional CSS. Paste the CSS and click Save.
- Child theme or snippets plugin: if you already keep custom CSS in a child theme's
style.cssor a code-snippets plugin, that works too.
Example 1 — Let Label Swatches Widen to Fit Their Text
Label swatches keep the round size of color swatches by default, so long labels are cut off ("Medium" shows as "Medi"). The quickest fix needs no CSS: set Swatch shape to Rounded square or Square (see Chapter 4), and labels widen to fit their text. If you want to keep round color swatches but give labels fully rounded, pill-shaped ends, use this CSS instead — it works on product pages and on shop and category cards:
body .chiseikoessw-swatch.chiseikoessw-swatch--label,
body .chiseikoessw-swatch.chiseikoessw-swatch--none {
width: auto !important;
min-width: var(--chiseikoessw-text-min-width) !important;
padding: var(--chiseikoessw-text-padding) !important;
border-radius: 9999px !important;
overflow: visible !important;
}
body .chiseikoessw-swatch.chiseikoessw-swatch--label .chiseikoessw-swatch__inner,
body .chiseikoessw-swatch.chiseikoessw-swatch--none .chiseikoessw-swatch__inner {
overflow: visible !important;
}
body .chiseikoessw-swatch.chiseikoessw-swatch--loop.chiseikoessw-swatch--label,
body .chiseikoessw-swatch.chiseikoessw-swatch--loop.chiseikoessw-swatch--none {
min-width: var(--chiseikoessw-text-min-width-sm) !important;
padding: var(--chiseikoessw-text-padding-sm) !important;
}
Color and image swatches are not affected.
Pro users: you do not need CSS for this. Choose Pill or Square as the default shape in Display Settings → Advanced Styling, or set either shape on just the label terms. See Chapter 10 — Advanced Styling.
Example 2 — Bigger Swatches on Phones and Tablets
On touch screens, swatches are 44 px by default. To make them larger there without changing desktop:
@media (pointer: coarse), (max-width: 768px) {
:root {
--chiseikoessw-swatch-size: 52px;
}
}
Use --chiseikoessw-swatch-size-sm instead to resize the swatches on shop and category cards.
Example 3 — More Space Between Swatches
:root {
--chiseikoessw-swatch-gap: 12px;
}
--chiseikoessw-swatch-gap controls product pages. Use --chiseikoessw-swatch-gap-sm for shop and category cards.
CSS Custom Properties
The plugin's styles read these custom properties. Set them on :root, as in the examples above, to change every swatch at once. Touch values apply on touch screens and on screens up to 768 px wide.
| Property | Default | Touch | Controls |
|---|---|---|---|
--chiseikoessw-swatch-size |
32px | 44px | Color and image swatch size on product pages; also the width of label swatches unless they widen to fit their text (Example 1) |
--chiseikoessw-swatch-size-sm |
32px | 44px | Swatch size on shop and category cards |
--chiseikoessw-swatch-gap |
8px | — | Space between swatches on product pages |
--chiseikoessw-swatch-gap-sm |
6px | — | Space between swatches on shop and category cards |
--chiseikoessw-swatch-border-width |
1px | — | Swatch border width |
--chiseikoessw-swatch-border-color |
rgba(0, 0, 0, 0.12) | — | Swatch border color |
--chiseikoessw-swatch-shadow |
0 1px 3px rgba(0, 0, 0, .08) | — | Resting shadow |
--chiseikoessw-swatch-selected-shadow |
0 0 0 2px (accent color) | — | Ring around the selected swatch |
--chiseikoessw-swatch-hover-scale |
1.08 | — | How much a swatch grows on hover (1 = no growth) |
--chiseikoessw-swatch-disabled-opacity |
0.45 | — | Opacity of unavailable and out-of-stock swatches |
--chiseikoessw-transition-speed |
0.2s | — | Hover and selection animation speed |
--chiseikoessw-text-height |
32px | 48px | Height of label swatches on product pages |
--chiseikoessw-text-min-width |
32px | 48px | Minimum width of label swatches |
--chiseikoessw-text-padding |
0 12px | 0 16px | Inner spacing of label swatches |
--chiseikoessw-text-font-size |
0.75rem | — | Label text size |
--chiseikoessw-text-font-weight |
600 | — | Label text weight |
--chiseikoessw-radio-dot |
16px | 20px | Radio button circle size |
--chiseikoessw-radio-min |
32px | 48px | Height and minimum width of radio swatches |
The -sm versions of the text properties (--chiseikoessw-text-height-sm, --chiseikoessw-text-min-width-sm, --chiseikoessw-text-padding-sm) apply to shop and category cards.
Settings that you save in the admin print their own values for some of these properties. When a setting and your CSS disagree, whichever loads later wins; Additional CSS normally loads last.
CSS Classes
Use these classes to target swatches in your own CSS.
| Class | Element |
|---|---|
.chiseikoessw-swatches |
A product-page swatch group (one per attribute). Its data-attribute_name holds the attribute, e.g. attribute_pa_size. |
.chiseikoessw-swatch |
One swatch button |
.chiseikoessw-swatch--color, --image, --label, --radio |
The swatch type |
.chiseikoessw-swatch--none |
A term with no swatch type, shown as plain text |
.chiseikoessw-swatch--loop |
A swatch on a shop or category card |
.chiseikoessw-swatch--selected |
The selected swatch |
[aria-disabled="true"] |
An unavailable or out-of-stock swatch |
For example, .chiseikoessw-swatches[data-attribute_name="attribute_pa_size"] .chiseikoessw-swatch targets only the Size swatches on product pages.
For Developers — PHP Filters and Actions
Add PHP in a child theme's functions.php or a code-snippets plugin.
Add your own class to one attribute's swatches
add_filter(
'chiseikoessw_swatch_button_classes',
function ( array $classes, int $term_id, string $type, $ctx ): array {
if ( 'pa_size' === $ctx->attribute ) {
$classes[] = 'my-size-swatch';
}
return $classes;
},
10,
4
);
$ctx describes the swatch being drawn: $ctx->attribute (e.g. pa_size), $ctx->term, $ctx->type, $ctx->product, $ctx->is_selected, and $ctx->context (single on product pages, loop on shop cards).
Hide shop-card swatches for some products
add_filter(
'chiseikoessw_render_loop_swatches',
function ( bool $render, $product ): bool {
if ( has_term( 'gift-sets', 'product_cat', $product->get_id() ) ) {
return false;
}
return $render;
},
10,
2
);
Replace gift-sets with your category's slug.
Reference
| Hook | Type | Arguments | Use it to |
|---|---|---|---|
chiseikoessw_swatch_button_classes |
Filter | $classes, $term_id, $type, $ctx |
Add or remove classes on a swatch button |
chiseikoessw_swatch_button_html |
Filter | $html, $ctx |
Change a swatch button's HTML |
chiseikoessw_swatch_group_html |
Filter | $html, $args |
Change a product-page swatch group's HTML |
chiseikoessw_render_loop_swatches |
Filter | $render, $product |
Turn shop-card swatches off for some products |
chiseikoessw_before_swatch_group |
Action | $attribute, $product |
Print markup before a product-page swatch group |
chiseikoessw_after_swatch_group |
Action | $attribute, $product |
Print markup after a product-page swatch group |
chiseikoessw_before_loop_swatches |
Action | $product |
Print markup before a shop card's swatches |
chiseikoessw_after_loop_swatches |
Action | $product |
Print markup after a shop card's swatches |
When you change HTML with a filter, escape anything you add with esc_html(), esc_attr(), or esc_url().