Woocommerce make some product attributes optional

I’m using Variation Swatches plugin by AOV UP. It converts simple view of woocommerce product with variations to image swatch like you can see below. I’ve got some variations of product that are like “subvariations” and I want to make it optional. Woocommerce won’t pass this product to cart if all of them are not chosen. This is the part of plugin code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public function get_swatch_html( $html, $args ) {
global $woocommerce_loop;
global $product;
$attr = TA_WCVS()->get_tax_attribute( $args['attribute'] );
//$attr = TA_WCVS()->$product->get_attributes();
// Return if this is normal attribute
if ( empty( $attr ) || ! $args['product'] instanceof WC_Product_Variable ) {
return $html;
}
$options = $args['options'];
$product = $args['product'];
$attribute_tax_name = $args['attribute'];
$class = "variation-selector variation-select-{$attr->attribute_type}";
$swatches = '';
$is_product_page = is_product();
$defined_limit = apply_filters( 'tawcvs_swatch_limit_number', 0 );
$out_of_stock_state = apply_filters( 'tawcvs_out_of_stock_state', '' );
//If this product has disabled the variation swatches
if ( $this->is_disabled_variation_swatches( $product ) ) {
return $html;
}
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute_tax_name ) ) {
$attributes = $product->get_variation_attributes();
$options = $attributes[ $attribute_tax_name ];
}
if ( empty( $attr->attribute_type ) ) {
return $html;
}
// Add new option for tooltip to $args variable.
$args['tooltip'] = apply_filters( 'tawcvs_tooltip_enabled', $this->is_tooltip_enabled() );
//Get the product variation detail for each attribute
//If there are more than one attributes, the first one will be applied
$collected_variations = array();
if ( TA_WC_Variation_Swatches::is_pro_addon_active() && ! $this->is_use_attribute_image_only() ) {
$collected_variations = TA_WC_Variation_Swatches::get_detailed_product_variations( $product, $attribute_tax_name );
}
if ( ! empty( $options ) && taxonomy_exists( $attribute_tax_name ) ) {
// Get terms if this is a taxonomy - ordered. We need the names too.
$terms = $this->get_product_variation_term( $product, $defined_limit, $attribute_tax_name, $options );
foreach ( $terms as $term ) {
//Check if we have the product variable for this attribute
if ( isset( $collected_variations[ $term->slug ] ) ) {
$args['variation_product'] = $collected_variations[ $term->slug ];
} else {
unset( $args['variation_product'] );
}
$swatches .= apply_filters( 'tawcvs_swatch_html', '', $term, $attr->attribute_type, $args, $product );
}
//If we are on shop/archived page (not product page), we will check the defined limit number of variations
//the product still have more variations -> show the view more icon
if ( ( ! $is_product_page || $woocommerce_loop['name'] == 'related' )
&& 0 < $defined_limit
&& count( $options ) > $defined_limit ) {
$swatches .= apply_filters( 'tawcvs_swatch_show_more_html', '', $product );
}
}
if ( ! empty( $swatches ) ) {
$class .= ' hidden';
$swatches = '<div id="attribute_' . esc_attr( $attribute_tax_name ) . '" class="tawcvs-swatches oss-' . $out_of_stock_state . '" data-attribute_name="attribute_' . esc_attr( $attribute_tax_name ) . '">' . $swatches . '</div>';
$html = '<div class="' . esc_attr( $class ) . '">' . $html . '</div>' . $swatches;
}
return $html;
}
add_filter('tawcvs_swatch_html', function( $html, $term, $type, $args) {
$selected = sanitize_title( $args['selected'] ) == $term->slug ? 'selected' : '';
$name = apply_filters( 'woocommerce_variation_option_name', $term->name ) ;
$tooltip = '';
/*if ($args['tooltip'] && $term->description) {
$tooltip = '<span class="swatch__tooltip">' . $term->description . '</span>';
}*/
switch ( $type ) {
case 'color':
$color = get_term_meta( $term->term_id, 'color', true );
list( $r, $g, $b ) = sscanf( $color, "#%02x%02x%02x" );
$html = sprintf(
'<span class="swatch swatch-color swatch-%s %s" style="background-color:%s;color:%s;" data-value="%s">%s%s</span>',
esc_attr( $term->slug ),
$selected,
esc_attr( $color ),
"rgba($r,$g,$b,0.5)",
esc_attr( $term->slug ),
$name,
$tooltip
);
break;
case 'image':
$image = get_term_meta( $term->term_id, 'image', true );
$image = $image ? wp_get_attachment_image_src($image, 'woocommerce_single') : '';
$image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png';
$label = esc_attr( $name );
$html = sprintf(
'<span class="swatch swatch-image swatch-%s %s" data-value="%s"><span class="swatch__tooltip">%s</span><span class="swatches_image-container"><img src="%s" alt="%s"></span>%s</span>',
esc_attr( $term->slug ),
$selected,
esc_attr( $term->slug ),
$term->description,
esc_url( $image ),
esc_attr( $name ),
$label
);
break;
case 'label':
$label = get_term_meta( $term->term_id, 'label', true );
$label = $label ? $label : $name;
$html = sprintf(
'<span class="swatch swatch-label swatch-%s %s" data-value="%s">%s%s</span>',
esc_attr( $term->slug ),
$selected,
esc_attr( $term->slug ),
$label,
$tooltip
);
break;
}
return $html;
}, 10, 4);
</code>
<code>public function get_swatch_html( $html, $args ) { global $woocommerce_loop; global $product; $attr = TA_WCVS()->get_tax_attribute( $args['attribute'] ); //$attr = TA_WCVS()->$product->get_attributes(); // Return if this is normal attribute if ( empty( $attr ) || ! $args['product'] instanceof WC_Product_Variable ) { return $html; } $options = $args['options']; $product = $args['product']; $attribute_tax_name = $args['attribute']; $class = "variation-selector variation-select-{$attr->attribute_type}"; $swatches = ''; $is_product_page = is_product(); $defined_limit = apply_filters( 'tawcvs_swatch_limit_number', 0 ); $out_of_stock_state = apply_filters( 'tawcvs_out_of_stock_state', '' ); //If this product has disabled the variation swatches if ( $this->is_disabled_variation_swatches( $product ) ) { return $html; } if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute_tax_name ) ) { $attributes = $product->get_variation_attributes(); $options = $attributes[ $attribute_tax_name ]; } if ( empty( $attr->attribute_type ) ) { return $html; } // Add new option for tooltip to $args variable. $args['tooltip'] = apply_filters( 'tawcvs_tooltip_enabled', $this->is_tooltip_enabled() ); //Get the product variation detail for each attribute //If there are more than one attributes, the first one will be applied $collected_variations = array(); if ( TA_WC_Variation_Swatches::is_pro_addon_active() && ! $this->is_use_attribute_image_only() ) { $collected_variations = TA_WC_Variation_Swatches::get_detailed_product_variations( $product, $attribute_tax_name ); } if ( ! empty( $options ) && taxonomy_exists( $attribute_tax_name ) ) { // Get terms if this is a taxonomy - ordered. We need the names too. $terms = $this->get_product_variation_term( $product, $defined_limit, $attribute_tax_name, $options ); foreach ( $terms as $term ) { //Check if we have the product variable for this attribute if ( isset( $collected_variations[ $term->slug ] ) ) { $args['variation_product'] = $collected_variations[ $term->slug ]; } else { unset( $args['variation_product'] ); } $swatches .= apply_filters( 'tawcvs_swatch_html', '', $term, $attr->attribute_type, $args, $product ); } //If we are on shop/archived page (not product page), we will check the defined limit number of variations //the product still have more variations -> show the view more icon if ( ( ! $is_product_page || $woocommerce_loop['name'] == 'related' ) && 0 < $defined_limit && count( $options ) > $defined_limit ) { $swatches .= apply_filters( 'tawcvs_swatch_show_more_html', '', $product ); } } if ( ! empty( $swatches ) ) { $class .= ' hidden'; $swatches = '<div id="attribute_' . esc_attr( $attribute_tax_name ) . '" class="tawcvs-swatches oss-' . $out_of_stock_state . '" data-attribute_name="attribute_' . esc_attr( $attribute_tax_name ) . '">' . $swatches . '</div>'; $html = '<div class="' . esc_attr( $class ) . '">' . $html . '</div>' . $swatches; } return $html; } add_filter('tawcvs_swatch_html', function( $html, $term, $type, $args) { $selected = sanitize_title( $args['selected'] ) == $term->slug ? 'selected' : ''; $name = apply_filters( 'woocommerce_variation_option_name', $term->name ) ; $tooltip = ''; /*if ($args['tooltip'] && $term->description) { $tooltip = '<span class="swatch__tooltip">' . $term->description . '</span>'; }*/ switch ( $type ) { case 'color': $color = get_term_meta( $term->term_id, 'color', true ); list( $r, $g, $b ) = sscanf( $color, "#%02x%02x%02x" ); $html = sprintf( '<span class="swatch swatch-color swatch-%s %s" style="background-color:%s;color:%s;" data-value="%s">%s%s</span>', esc_attr( $term->slug ), $selected, esc_attr( $color ), "rgba($r,$g,$b,0.5)", esc_attr( $term->slug ), $name, $tooltip ); break; case 'image': $image = get_term_meta( $term->term_id, 'image', true ); $image = $image ? wp_get_attachment_image_src($image, 'woocommerce_single') : ''; $image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png'; $label = esc_attr( $name ); $html = sprintf( '<span class="swatch swatch-image swatch-%s %s" data-value="%s"><span class="swatch__tooltip">%s</span><span class="swatches_image-container"><img src="%s" alt="%s"></span>%s</span>', esc_attr( $term->slug ), $selected, esc_attr( $term->slug ), $term->description, esc_url( $image ), esc_attr( $name ), $label ); break; case 'label': $label = get_term_meta( $term->term_id, 'label', true ); $label = $label ? $label : $name; $html = sprintf( '<span class="swatch swatch-label swatch-%s %s" data-value="%s">%s%s</span>', esc_attr( $term->slug ), $selected, esc_attr( $term->slug ), $label, $tooltip ); break; } return $html; }, 10, 4); </code>
public function get_swatch_html( $html, $args ) {
        global $woocommerce_loop;
                global $product;

        $attr = TA_WCVS()->get_tax_attribute( $args['attribute'] );
                //$attr = TA_WCVS()->$product->get_attributes();

        // Return if this is normal attribute
        if ( empty( $attr ) || ! $args['product'] instanceof WC_Product_Variable ) {
            return $html;
        }

        $options = $args['options'];
        $product = $args['product'];
        $attribute_tax_name = $args['attribute'];
        $class = "variation-selector variation-select-{$attr->attribute_type}";
        $swatches = '';
        $is_product_page = is_product();
        $defined_limit = apply_filters( 'tawcvs_swatch_limit_number', 0 );
        $out_of_stock_state = apply_filters( 'tawcvs_out_of_stock_state', '' );

        //If this product has disabled the variation swatches
        if ( $this->is_disabled_variation_swatches( $product ) ) {
            return $html;
        }

        if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute_tax_name ) ) {
            $attributes = $product->get_variation_attributes();
            $options = $attributes[ $attribute_tax_name ];
        }


        if ( empty( $attr->attribute_type ) ) {
            return $html;
        }

        // Add new option for tooltip to $args variable.
        $args['tooltip'] = apply_filters( 'tawcvs_tooltip_enabled', $this->is_tooltip_enabled() );

        //Get the product variation detail for each attribute
        //If there are more than one attributes, the first one will be applied
        $collected_variations = array();

        if ( TA_WC_Variation_Swatches::is_pro_addon_active() && ! $this->is_use_attribute_image_only() ) {
            $collected_variations = TA_WC_Variation_Swatches::get_detailed_product_variations( $product, $attribute_tax_name );
        }

        if ( ! empty( $options ) && taxonomy_exists( $attribute_tax_name ) ) {
            // Get terms if this is a taxonomy - ordered. We need the names too.
            $terms = $this->get_product_variation_term( $product, $defined_limit, $attribute_tax_name, $options );

            foreach ( $terms as $term ) {

                //Check if we have the product variable for this attribute
                if ( isset( $collected_variations[ $term->slug ] ) ) {
                    $args['variation_product'] = $collected_variations[ $term->slug ];
                } else {
                    unset( $args['variation_product'] );
                }

                $swatches .= apply_filters( 'tawcvs_swatch_html', '', $term, $attr->attribute_type, $args, $product );

            }
            //If we are on shop/archived page (not product page), we will check the defined limit number of variations
            //the product still have more variations -> show the view more icon
            if ( ( ! $is_product_page || $woocommerce_loop['name'] == 'related' )
                 && 0 < $defined_limit
                 && count( $options ) > $defined_limit ) {
                $swatches .= apply_filters( 'tawcvs_swatch_show_more_html', '', $product );
            }
        }

        if ( ! empty( $swatches ) ) {
            $class .= ' hidden';
                            $swatches = '<div id="attribute_' . esc_attr( $attribute_tax_name ) . '" class="tawcvs-swatches oss-' . $out_of_stock_state . '" data-attribute_name="attribute_' . esc_attr( $attribute_tax_name ) . '">' . $swatches . '</div>';
            $html = '<div class="' . esc_attr( $class ) . '">' . $html . '</div>' . $swatches;
        }
        return $html;
    }

add_filter('tawcvs_swatch_html', function( $html, $term, $type, $args) {
    $selected = sanitize_title( $args['selected'] ) == $term->slug ? 'selected' : '';
        $name     =  apply_filters( 'woocommerce_variation_option_name', $term->name ) ;
        $tooltip  = '';

        /*if ($args['tooltip'] && $term->description) {
            $tooltip = '<span class="swatch__tooltip">' . $term->description . '</span>';
        }*/

        switch ( $type ) {
            case 'color':
                $color = get_term_meta( $term->term_id, 'color', true );
                list( $r, $g, $b ) = sscanf( $color, "#%02x%02x%02x" );
                $html = sprintf(
                    '<span class="swatch swatch-color swatch-%s %s" style="background-color:%s;color:%s;" data-value="%s">%s%s</span>',
                    esc_attr( $term->slug ),
                    $selected,
                    esc_attr( $color ),
                    "rgba($r,$g,$b,0.5)",
                    esc_attr( $term->slug ),
                    $name,
                    $tooltip
                );
                break;

            case 'image':
                $image = get_term_meta( $term->term_id, 'image', true );
                                $image = $image ? wp_get_attachment_image_src($image, 'woocommerce_single') : '';
                $image = $image ? $image[0] : WC()->plugin_url() . '/assets/images/placeholder.png';
                $label = esc_attr( $name );
                                    $html  = sprintf(
                    '<span class="swatch swatch-image swatch-%s %s" data-value="%s"><span class="swatch__tooltip">%s</span><span class="swatches_image-container"><img src="%s" alt="%s"></span>%s</span>',
                    esc_attr( $term->slug ),
                    $selected,
                    esc_attr( $term->slug ),
                                        $term->description,
                    esc_url( $image ),
                    esc_attr( $name ),
                                        $label
                                    );
                break;

            case 'label':
                $label = get_term_meta( $term->term_id, 'label', true );
                $label = $label ? $label : $name;
                $html  = sprintf(
                    '<span class="swatch swatch-label swatch-%s %s" data-value="%s">%s%s</span>',
                    esc_attr( $term->slug ),
                    $selected,
                    esc_attr( $term->slug ),
                    $label,
                    $tooltip
                );
                break;
        }

        return $html;
}, 10, 4);

it shows like this

I’ve got some code that makes attributes which are not set as visible in variations optional taken from user @Mtxz from here:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>/**
* List available attributes on the product page in a drop-down selection
*/
function list_attributes_on_product_page() {
global $product;
$attributes = $product->get_attributes();
if ( ! $attributes ) {
return;
}
//from original script, but here we want to use it for variable products
/*if ($product->is_type( 'variable' )) {
return;
}*/
echo '<div style="padding-bottom:15px;">';
foreach ( $attributes as $attribute ) {
//If product is variable, and attribute is used for variation: woocommerce already handle this input - so it can also be used with attributes of simple products (not variables)
if($product->is_type( 'variable' ) && $attribute['variation']) {
continue;
}
//get taxonomy for the attribute - eg: Size
$taxonomy = get_taxonomy($attribute['name']);
//get terms - eg: small
$options = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'all' ) );
$label = str_replace('Product ', '', $taxonomy->label);
//display select input
?>
<div style="padding-bottom:8px;">
<label for="attribute[<?php echo $attribute['id']; ?>]"><?php echo $label; ?></label>
<br />
<!-- add required attribute or not, handle default with "selected" attribute depending your needs -->
<select name="attribute[<?php echo $attribute['id']; ?>]" id="attribute[<?php echo $attribute['id']; ?>]">
<option value disabled selected>Choose an option</option>
<?php foreach ( $options as $pa ): ?>
<option value="<?php echo $pa->name; ?>"><?php echo $pa->name; ?></option>
<?php endforeach; ?>
</select>
</div>
<?php
}
echo '</div>';
}
add_action('woocommerce_before_add_to_cart_button', 'list_attributes_on_product_page');
/**
* Add selected attributes to cart items
*/
add_filter('woocommerce_add_cart_item_data', 'add_attributes_to_cart_item', 10, 3 );
function add_attributes_to_cart_item( $cart_item_data, $product_id, $variation_id ) {
$attributes = $_POST['attribute'] ?? null;
if (empty( $attributes ) ) {
return $cart_item_data;
}
$cart_item_data['attributes'] = serialize($attributes);
return $cart_item_data;
}
/**
* Display attributes in cart
*/
add_filter( 'woocommerce_get_item_data', 'display_attributes_in_cart', 10, 2 );
function display_attributes_in_cart( $item_data, $cart_item ) {
if ( empty( $cart_item['attributes'] ) ) {
return $item_data;
}
foreach (unserialize($cart_item['attributes']) as $attributeID => $value) {
$attribute = wc_get_attribute($attributeID);
$item_data[] = array(
'key' => $attribute->name,
'value' => $value,
'display' => '',
);
}
return $item_data;
}
/**
* Add attribute data to order items
*/
add_action( 'woocommerce_checkout_create_order_line_item', 'add_attributes_to_order_items', 10, 4 );
function add_attributes_to_order_items( $item, $cart_item_key, $values, $order ) {
if ( empty( $values['attributes'] ) ) {
return;
}
foreach (unserialize($values['attributes']) as $attributeID => $value) {
$attribute = wc_get_attribute($attributeID);
$item->add_meta_data( $attribute->name, $value );
}
}
</code>
<code>/** * List available attributes on the product page in a drop-down selection */ function list_attributes_on_product_page() { global $product; $attributes = $product->get_attributes(); if ( ! $attributes ) { return; } //from original script, but here we want to use it for variable products /*if ($product->is_type( 'variable' )) { return; }*/ echo '<div style="padding-bottom:15px;">'; foreach ( $attributes as $attribute ) { //If product is variable, and attribute is used for variation: woocommerce already handle this input - so it can also be used with attributes of simple products (not variables) if($product->is_type( 'variable' ) && $attribute['variation']) { continue; } //get taxonomy for the attribute - eg: Size $taxonomy = get_taxonomy($attribute['name']); //get terms - eg: small $options = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'all' ) ); $label = str_replace('Product ', '', $taxonomy->label); //display select input ?> <div style="padding-bottom:8px;"> <label for="attribute[<?php echo $attribute['id']; ?>]"><?php echo $label; ?></label> <br /> <!-- add required attribute or not, handle default with "selected" attribute depending your needs --> <select name="attribute[<?php echo $attribute['id']; ?>]" id="attribute[<?php echo $attribute['id']; ?>]"> <option value disabled selected>Choose an option</option> <?php foreach ( $options as $pa ): ?> <option value="<?php echo $pa->name; ?>"><?php echo $pa->name; ?></option> <?php endforeach; ?> </select> </div> <?php } echo '</div>'; } add_action('woocommerce_before_add_to_cart_button', 'list_attributes_on_product_page'); /** * Add selected attributes to cart items */ add_filter('woocommerce_add_cart_item_data', 'add_attributes_to_cart_item', 10, 3 ); function add_attributes_to_cart_item( $cart_item_data, $product_id, $variation_id ) { $attributes = $_POST['attribute'] ?? null; if (empty( $attributes ) ) { return $cart_item_data; } $cart_item_data['attributes'] = serialize($attributes); return $cart_item_data; } /** * Display attributes in cart */ add_filter( 'woocommerce_get_item_data', 'display_attributes_in_cart', 10, 2 ); function display_attributes_in_cart( $item_data, $cart_item ) { if ( empty( $cart_item['attributes'] ) ) { return $item_data; } foreach (unserialize($cart_item['attributes']) as $attributeID => $value) { $attribute = wc_get_attribute($attributeID); $item_data[] = array( 'key' => $attribute->name, 'value' => $value, 'display' => '', ); } return $item_data; } /** * Add attribute data to order items */ add_action( 'woocommerce_checkout_create_order_line_item', 'add_attributes_to_order_items', 10, 4 ); function add_attributes_to_order_items( $item, $cart_item_key, $values, $order ) { if ( empty( $values['attributes'] ) ) { return; } foreach (unserialize($values['attributes']) as $attributeID => $value) { $attribute = wc_get_attribute($attributeID); $item->add_meta_data( $attribute->name, $value ); } } </code>
/**
 * List available attributes on the product page in a drop-down selection
 */
function list_attributes_on_product_page() {
    global $product;
    $attributes = $product->get_attributes();

    if ( ! $attributes ) {
        return;
    }

    //from original script, but here we want to use it for variable products
    /*if ($product->is_type( 'variable' )) {
        return;
    }*/

    echo '<div style="padding-bottom:15px;">';

    foreach ( $attributes as $attribute ) {

        //If product is variable, and attribute is used for variation: woocommerce already handle this input - so it can also be used with attributes of simple products (not variables)
    if($product->is_type( 'variable' ) && $attribute['variation']) {
        continue;
    }

        //get taxonomy for the attribute - eg: Size
        $taxonomy = get_taxonomy($attribute['name']);

        //get terms - eg: small
        $options = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'all' ) );
        $label = str_replace('Product ', '', $taxonomy->label);
        //display select input
        ?>
        <div style="padding-bottom:8px;">
            <label for="attribute[<?php echo $attribute['id']; ?>]"><?php echo $label; ?></label>
            <br />
            <!-- add required attribute or not, handle default with "selected" attribute depending your needs -->
            <select name="attribute[<?php echo $attribute['id']; ?>]" id="attribute[<?php echo $attribute['id']; ?>]">
                <option value disabled selected>Choose an option</option>
                <?php foreach ( $options as $pa ): ?>
                    <option value="<?php echo $pa->name; ?>"><?php echo $pa->name; ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <?php
    }

    echo '</div>';
}
add_action('woocommerce_before_add_to_cart_button', 'list_attributes_on_product_page');

/**
 * Add selected attributes to cart items
 */
add_filter('woocommerce_add_cart_item_data', 'add_attributes_to_cart_item', 10, 3 );
function add_attributes_to_cart_item( $cart_item_data, $product_id, $variation_id ) {
    $attributes = $_POST['attribute'] ?? null;

    if (empty( $attributes ) ) {
        return $cart_item_data;
    }

    $cart_item_data['attributes'] = serialize($attributes);

    return $cart_item_data;
}

/**
 * Display attributes in cart
 */
add_filter( 'woocommerce_get_item_data', 'display_attributes_in_cart', 10, 2 );
function display_attributes_in_cart( $item_data, $cart_item ) {
    if ( empty( $cart_item['attributes'] ) ) {
        return $item_data;
    }

    foreach (unserialize($cart_item['attributes']) as $attributeID => $value) {
        $attribute = wc_get_attribute($attributeID);
        $item_data[] = array(
            'key'     => $attribute->name,
            'value'   => $value,
            'display' => '',
        );
    }

    return $item_data;
}

/**
 * Add attribute data to order items
 */
add_action( 'woocommerce_checkout_create_order_line_item', 'add_attributes_to_order_items', 10, 4 );
function add_attributes_to_order_items( $item, $cart_item_key, $values, $order ) {
    if ( empty( $values['attributes'] ) ) {
        return;
    }

    foreach (unserialize($values['attributes']) as $attributeID => $value) {
        $attribute = wc_get_attribute($attributeID);
        $item->add_meta_data( $attribute->name, $value );
    }
}

It lists attributes of product wich are not set as variations (they are turned off to show on product page, but they’re still sticked to this product). Unfortunately they’re not parsed by WC plugin to format them to images like on screen above:
select elements

Any clues how to make it working together?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật