Automattic\WooCommerce\Blocks\BlockTypes

CouponCode::resolve_background_color │ private │ WC 1.0

Resolve background color from attributes, translating color slugs if needed.

Метод класса: CouponCode{}

Хуков нет.

Возвращает

string. Resolved color value or default.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->resolve_background_color( $attributes, $rendering_context ): string;
$attributes(массив) (обязательный)
Block attributes.
$rendering_context(Rendering_Context) (обязательный)
Rendering context.

Код CouponCode::resolve_background_color() WC 11.2.1

private function resolve_background_color( array $attributes, Rendering_Context $rendering_context ): string {
	if ( empty( $attributes['backgroundColor'] ) ) {
		return self::DEFAULT_STYLES['background-color'];
	}

	$color_slug = $attributes['backgroundColor'];

	// Try to get color from normalized styles (handles slug translation).
	$normalized = Styles_Helper::get_normalized_block_styles( $attributes, $rendering_context );
	$color      = $normalized['color']['background'] ?? '';

	if ( $this->is_css_color_value( $color ) ) {
		return $color;
	}

	// Fallback: try direct translation if normalization returned the slug unchanged.
	$translated = $rendering_context->translate_slug_to_color( $color_slug );
	if ( $this->is_css_color_value( $translated ) ) {
		return $translated;
	}

	return self::DEFAULT_STYLES['background-color'];
}