WC_Admin_Marketplace_Promotions::maybe_enqueue_orders_promo_cardpublic staticWC 11.0.0

Enqueue the Orders-screen promo card script and localize the resolved promo.

The Orders list is a classic admin page, so the card is mounted by a wp-admin-scripts entry that inserts it above the orders table (see ShippingLabelBanner for the same enqueue pattern). The promotion is rule-resolved server-side and passed to the script, so no additional data is shared with WooCommerce.com.

Method of the class: WC_Admin_Marketplace_Promotions{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Admin_Marketplace_Promotions::maybe_enqueue_orders_promo_card();

Changelog

Since 11.0.0 Introduced.

WC_Admin_Marketplace_Promotions::maybe_enqueue_orders_promo_card() code WC 11.0.0

public static function maybe_enqueue_orders_promo_card() {
	if ( ! self::is_orders_screen() ) {
		return;
	}

	$card = self::get_orders_promo_card();
	if ( null === $card ) {
		return;
	}

	WCAdminAssets::register_script( 'wp-admin-scripts', 'marketplace-orders-promo', true );

	// Pass the REST dismiss URL + nonce so the script persists a dismissal with a plain fetch.
	// rest_url() yields a working URL under any permalink structure, and this avoids depending
	// on apiFetch being configured on this classic (non-SPA) admin page.
	$payload = array_merge(
		$card,
		array(
			'dismiss_url'   => esc_url_raw( rest_url( 'wc-admin/marketplace-promotions/dismiss' ) ),
			'dismiss_nonce' => wp_create_nonce( 'wp_rest' ),
		)
	);
	wp_add_inline_script(
		'wc-admin-marketplace-orders-promo',
		'window.wcOrdersPromo = ' . wp_json_encode( $payload, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) . ';',
		'before'
	);

	// Enqueue the card stylesheet under a unique handle. WCAdminAssets::register_style() would
	// register it as the shared `wc-admin-style` handle, which collides with other Orders-screen
	// styles (e.g. Fulfillments) so that whichever enqueues first wins and the other is dropped.
	$style_handle = 'wc-admin-marketplace-orders-promo';
	wp_enqueue_style(
		$style_handle,
		WCAdminAssets::get_url( 'marketplace-orders-promo/style', 'css' ),
		array( 'wp-components' ),
		WCAdminAssets::get_file_version( 'css' )
	);
	wp_style_add_data( $style_handle, 'rtl', 'replace' );
}