Automattic\WooCommerce\Blocks\BlockTypes

CouponCode::resolve_background_colorprivateWC 1.0

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

Method of the class: CouponCode{}

No Hooks.

Returns

String. Resolved color value or default.

Usage

// private - for code of main (parent) class only
$result = $this->resolve_background_color( $attributes, $rendering_context ): string;
$attributes(array) (required)
Block attributes.
$rendering_context(Rendering_Context) (required)
Rendering context.

CouponCode::resolve_background_color() code WC 10.8.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'];
}