Is it possible to add swatches like variables have, on composite product?
https://woocommerce.com/document/composite-products/
I have this little snippet, that adds the label of color attribute – but it is not shown as an swatch:
if( $product->is_type(‘composite’) ) {
$attributes = $product->get_attributes();
if( isset($attributes[‘pa_color’]) ) {
$attribute_name = $attributes[‘pa_color’]->get_name();
$attribute_value = $product->get_attribute($attribute_name);
$attribute_value = str_replace(‘ ‘, ”, $attribute_value);
$attribute_value = strtolower($attribute_value);
$attribute_value = explode(‘,’, $attribute_value);
$attribute_value = array_unique($attribute_value);
$attribute_value = implode(‘,’, $attribute_value);
$attribute_value = str_replace(‘,’, ‘ ‘, $attribute_value);
echo ‘<div class=”swatch-container”><span class=”swatch-label”>Color:</span><span class=”swatch-value”>’ . $attribute_value . ‘</span></div>’;
}
}
}
I know this is out of support for the theme, but I am guessing you may have encountered this question before?