WooCommerce Code Reference

WC_Admin_Marketplace_Promotions
in package

WC_Admin_Marketplace_Promotions class.

Table of Contents

CRON_NAME  = 'woocommerce_marketplace_cron_fetch_promotions'
PROMOTIONS_API_URL  = 'https://woocommerce.com/wp-json/wccom-extensions/3.0/promotions'
TRANSIENT_LIFE_SPAN  = DAY_IN_SECONDS
TRANSIENT_NAME  = 'woocommerce_marketplace_promotions_v2'
$locale  : string
The user's locale, for example en_US.
clear_cron_event()  : void
When WooCommerce is disabled, clear the WP Cron event we use to fetch promotions.
clear_deprecated_action()  : mixed
We can't clear deprecated action from AS when it's running, so we schedule a new single action to clear the deprecated `woocommerce_marketplace_fetch_promotions` action.
clear_deprecated_scheduled_event()  : void
Clear deprecated scheduled action that was used to fetch promotions in WooCommerce 8.8.
filter_marketplace_menu_items()  : array<string|int, mixed>
Callback for the `woocommerce_marketplace_menu_items` filter in `Automattic\WooCommerce\Internal\Admin\Marketplace::get_marketplace_pages`.
get_active_promotions()  : mixed
Get active Marketplace promotions from the transient.
init()  : void
On all admin pages, try go get Marketplace promotions every day.
update_promotions()  : void
Fetch promotions from the API and store them in a transient.
append_bubble()  : string
Return the markup for a menu item bubble with a given text.
fetch_marketplace_promotions()  : array<string|int, mixed>
Get promotions to show in the Woo in-app marketplace and load them into a transient with a 12-hour life. Run as a recurring scheduled action.
filter_out_inactive_promotions()  : array<string|int, mixed>
Find promotions that are still active – they have a date range that includes the current date.
get_promotions_of_format()  : array<string|int, mixed>
From the array of promotions, select those of a given format.
maybe_show_bubble_promotions()  : void
If there's an active promotion of the format `menu_bubble`, add a filter to show a bubble on the Extensions item in the WooCommerce menu.
merge_promos()  : array<string|int, mixed>
Promos arrive in the array of promotions as an array of arrays with the key 'promos'.
schedule_cron_event()  : void
Schedule a daily cron event to fetch promotions.

Constants

Properties

Methods

clear_deprecated_action()

We can't clear deprecated action from AS when it's running, so we schedule a new single action to clear the deprecated `woocommerce_marketplace_fetch_promotions` action.

public static clear_deprecated_action() : mixed
Return values
mixed

clear_deprecated_scheduled_event()

Clear deprecated scheduled action that was used to fetch promotions in WooCommerce 8.8.

public static clear_deprecated_scheduled_event() : void

Replaced with a transient in WooCommerce 9.0.

Return values
void

filter_marketplace_menu_items()

Callback for the `woocommerce_marketplace_menu_items` filter in `Automattic\WooCommerce\Internal\Admin\Marketplace::get_marketplace_pages`.

public static filter_marketplace_menu_items(array<string|int, mixed> $menu_items[, array<string|int, mixed>|null $promotion = array() ]) : array<string|int, mixed>

At the moment, the Extensions page is the only page in $menu_items. Adds a bubble to the menu item.

Parameters
$menu_items : array<string|int, mixed>

Arrays representing items in nav menu.

$promotion : array<string|int, mixed>|null = array()

Data about a promotion from the WooCommerce.com API.

Return values
array<string|int, mixed>

get_active_promotions()

Get active Marketplace promotions from the transient.

public static get_active_promotions() : mixed

Use woocommerce_marketplace_suppress_promotions filter to suppress promotions.

Tags
since
9.0
Return values
mixed

init()

On all admin pages, try go get Marketplace promotions every day.

public static init() : void

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.

Return values
void

append_bubble()

Return the markup for a menu item bubble with a given text.

private static append_bubble(string $menu_item_text, string $bubble_text) : string
Parameters
$menu_item_text : string

Text of menu item we want to change.

$bubble_text : string

Text of bubble.

Return values
string

fetch_marketplace_promotions()

Get promotions to show in the Woo in-app marketplace and load them into a transient with a 12-hour life. Run as a recurring scheduled action.

private static fetch_marketplace_promotions() : array<string|int, mixed>
Return values
array<string|int, mixed>

filter_out_inactive_promotions()

Find promotions that are still active – they have a date range that includes the current date.

private static filter_out_inactive_promotions([array<string|int, mixed>|null $promotions = array() ]) : array<string|int, mixed>
Parameters
$promotions : array<string|int, mixed>|null = array()

Data about current promotions.

Return values
array<string|int, mixed>

get_promotions_of_format()

From the array of promotions, select those of a given format.

private static get_promotions_of_format([array<string|int, mixed>|null $promotions = array() ][, string|null $format = '' ]) : array<string|int, mixed>
Parameters
$promotions : array<string|int, mixed>|null = array()

Array of data about promotions of all formats.

$format : string|null = ''

Format we want to filter for.

Return values
array<string|int, mixed>

maybe_show_bubble_promotions()

If there's an active promotion of the format `menu_bubble`, add a filter to show a bubble on the Extensions item in the WooCommerce menu.

private static maybe_show_bubble_promotions() : void

Use woocommerce_marketplace_suppress_promotions filter to suppress the bubble.

Tags
throws
Exception

If we are unable to create a DateTime from the date_to_gmt.

Return values
void

merge_promos()

Promos arrive in the array of promotions as an array of arrays with the key 'promos'.

private static merge_promos([array<string|int, mixed>|null $promotions = array() ]) : array<string|int, mixed>

We merge them into the main array.

Parameters
$promotions : array<string|int, mixed>|null = array()

Promotions data received from WCCOM. May have an element with the key 'promos', which contains an array.

Return values
array<string|int, mixed>