WC_Admin_Marketplace_Promotions::initpublic staticWC 1.0

On all admin pages, try go get Marketplace promotions every day. Shows notice and adds menu badge to WooCommerce Extensions item if the promotions API requests them.

WC_Admin calls this method when it is instantiated during is_admin requests.

Method of the class: WC_Admin_Marketplace_Promotions{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Admin_Marketplace_Promotions::init();

WC_Admin_Marketplace_Promotions::init() code WC 11.0.0

public static function init() {
	// A legacy hook that can be triggered by action scheduler.
	add_action( 'woocommerce_marketplace_fetch_promotions', array( __CLASS__, 'clear_deprecated_action' ) );
	add_action(
		'woocommerce_marketplace_fetch_promotions_clear',
		array(
			__CLASS__,
			'clear_deprecated_scheduled_event',
		)
	);

	// Fetch promotions from the API and store them in a transient.
	add_action( self::CRON_NAME, array( __CLASS__, 'update_promotions' ) );

	// Registered on every request so the promo dismissal endpoint is available; the
	// rest_api_init action only fires during REST requests, and init (priority 11) runs first.
	add_action( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ) );

	if (
		( defined( 'DOING_AJAX' ) && DOING_AJAX )
		|| ( defined( 'DOING_CRON' ) && DOING_CRON )
		|| ( defined( 'WP_CLI' ) && WP_CLI )
	) {
		return;
	}

	if ( ! is_admin() ) {
		return;
	}

	self::schedule_cron_event();

	register_deactivation_hook( WC_PLUGIN_FILE, array( __CLASS__, 'clear_cron_event' ) );

	self::$locale = ( self::$locale ?? get_user_locale() ) ?? 'en_US';
	self::maybe_show_bubble_promotions();

	// Contextual promo card on the Orders list (a classic, non-SPA admin page). The script
	// inserts the card above the orders table using the promo data localized in the enqueue
	// step, which works the same on HPOS and the legacy posts list.
	add_action( 'admin_enqueue_scripts', array( __CLASS__, 'maybe_enqueue_orders_promo_card' ) );
}