Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_color_value()public staticWC 1.0

If color value is in preset format, convert it to a CSS var. Else return same value For example: "var:preset|color|pale-pink" -> "var(--wp--preset--color--pale-pink)" "#98b66e" -> "#98b66e"

Method of the class: StyleAttributesUtils{}

No Hooks.

Return

(String).

Usage

$result = StyleAttributesUtils::get_color_value( $color_value );
$color_value(string) (required)
value to be processed.

StyleAttributesUtils::get_color_value() code WC 9.4.2

public static function get_color_value( $color_value ) {
	if ( is_string( $color_value ) && str_contains( $color_value, 'var:preset|color|' ) ) {
		$color_value = str_replace( 'var:preset|color|', '', $color_value );
		return sprintf( 'var(--wp--preset--color--%s)', $color_value );
	}

	return $color_value;
}