WC_Admin_Marketplace_Promotions::resolve_rule_based_promotionsprivate staticWC 1.0

Evaluate locally targeted promotions before they are exposed to JS.

Supported stores convert matching rule-based promos into standard promo cards. Unsupported stores ignore the custom format entirely.

Method of the class: WC_Admin_Marketplace_Promotions{}

No Hooks.

Returns

Array.

Usage

$result = WC_Admin_Marketplace_Promotions::resolve_rule_based_promotions( $promotions ): array;
$promotions(array) (required)
Promotions data received from WCCOM.

WC_Admin_Marketplace_Promotions::resolve_rule_based_promotions() code WC 11.0.0

private static function resolve_rule_based_promotions( array $promotions ): array {
	$resolved_promotions = array();

	foreach ( $promotions as $promotion ) {
		if ( ! is_array( $promotion ) ) {
			$resolved_promotions[] = $promotion;
			continue;
		}

		if ( self::RULE_BASED_FORMAT !== ( $promotion['format'] ?? '' ) ) {
			$resolved_promotions[] = $promotion;
			continue;
		}

		if ( ! self::promotion_rules_pass( $promotion['local_rules'] ?? array() ) ) {
			continue;
		}

		unset( $promotion['local_rules'] );
		$promotion['format']   = 'promo-card';
		$resolved_promotions[] = $promotion;
	}

	return $resolved_promotions;
}