WC_Admin_Marketplace_Promotions::filter_marketplace_menu_items()public staticWC 1.0

Callback for the woocommerce_marketplace_menu_items in Automattic\WooCommerce\Internal\Admin\Marketplace::get_marketplace_pages. At the moment, the Extensions page is the only page in $menu_items. Adds a bubble to the menu item.

Method of the class: WC_Admin_Marketplace_Promotions{}

No Hooks.

Return

Array.

Usage

$result = WC_Admin_Marketplace_Promotions::filter_marketplace_menu_items( $menu_items, $promotion ): array;
$menu_items(array) (required)
Arrays representing items in nav menu.
$promotion(?array)
Data about a promotion from the WooCommerce.com API.
Default: array()

WC_Admin_Marketplace_Promotions::filter_marketplace_menu_items() code WC 9.8.1

public static function filter_marketplace_menu_items( $menu_items, $promotion = array() ): array {
	if ( ! isset( $promotion['menu_item_id'] ) || ! isset( $promotion['content'] ) ) {
		return $menu_items;
	}
	foreach ( $menu_items as $index => $menu_item ) {
		if (
			'woocommerce' === $menu_item['parent']
			&& $promotion['menu_item_id'] === $menu_item['id']
		) {
			$bubble_text                   = $promotion['content'][ self::$locale ] ?? ( $promotion['content']['en_US'] ?? __( 'Sale', 'woocommerce' ) );
			$menu_items[ $index ]['title'] = self::append_bubble( $menu_item['title'], $bubble_text );

			break;
		}
	}

	return $menu_items;
}