Automattic\WooCommerce\Internal\ShopperLists
ShopperListRenderer::get_variation_label
Build a comma-separated variation label like "Color: Blue, Size: M".
Method of the class: ShopperListRenderer{}
No Hooks.
Returns
String.
Usage
$result = ShopperListRenderer::get_variation_label( $item ): string;
- $item(array) (required)
- .
ShopperListRenderer::get_variation_label() ShopperListRenderer::get variation label code WC 10.9.1
public static function get_variation_label( array $item ): string {
$variation = $item['variation'] ?? array();
if ( ! is_array( $variation ) || empty( $variation ) ) {
return '';
}
$parts = array();
foreach ( $variation as $entry ) {
if ( ! is_array( $entry ) ) {
continue;
}
$attribute = isset( $entry['attribute'] ) ? html_entity_decode( (string) $entry['attribute'], ENT_QUOTES, 'UTF-8' ) : '';
$value = isset( $entry['value'] ) ? html_entity_decode( (string) $entry['value'], ENT_QUOTES, 'UTF-8' ) : '';
if ( '' === $attribute && '' === $value ) {
continue;
}
$parts[] = $attribute . ': ' . $value;
}
return implode( ', ', $parts );
}