Automattic\WooCommerce\Internal\ProductAttributes
VisualAttributeTermMeta::get_swatch_style
Build an inline swatch style from a normalized visual value.
Метод класса: VisualAttributeTermMeta{}
Хуков нет.
Возвращает
string.
Использование
$result = VisualAttributeTermMeta::get_swatch_style( $visual ): string;
- $visual(array{type?: string, value?: string}) (обязательный)
- Normalized visual value.
Список изменений
| С версии 10.9.0 | Введена. |
Код VisualAttributeTermMeta::get_swatch_style() VisualAttributeTermMeta::get swatch style WC 11.2.2
public static function get_swatch_style( array $visual ): string {
$type = isset( $visual['type'] ) ? (string) $visual['type'] : self::TYPE_NONE;
$value = isset( $visual['value'] ) ? (string) $visual['value'] : '';
if ( self::TYPE_IMAGE === $type ) {
$image = esc_url_raw( $value );
if ( $image ) {
return sprintf( "background-image:url('%s')", str_replace( "'", '%27', $image ) );
}
}
if ( self::TYPE_COLOR === $type ) {
$color = sanitize_hex_color( $value );
if ( $color ) {
return sprintf( 'background-color:%s', $color );
}
}
return '';
}