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.

Метод класса: WC_Admin_Marketplace_Promotions{}

Хуков нет.

Возвращает

Массив.

Использование

$result = WC_Admin_Marketplace_Promotions::filter_marketplace_menu_items( $menu_items, $promotion ): array;
$menu_items(массив) (обязательный)
Arrays representing items in nav menu.
$promotion(?array)
Data about a promotion from the WooCommerce.com API.
По умолчанию: array()

Код WC_Admin_Marketplace_Promotions::filter_marketplace_menu_items() WC 9.4.2

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;
}