Automattic\WooCommerce\Internal\Admin

WcPaySubscriptionsPage::restructure_menu_order()publicWC 1.0

Reorders the default WC admin menu items to ensure the Subscriptions item comes after orders.

{} Это метод класса: WcPaySubscriptionsPage{}

Хуков нет.

Возвращает

null. Ничего.

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

$WcPaySubscriptionsPage = new WcPaySubscriptionsPage();
$WcPaySubscriptionsPage->restructure_menu_order();

Заметки

  • Смотрите: Automattic\WooCommerce\Internal\Admin[Homescreen::update_link_structure()](/plugin/woocommerce/function/Homescreen::update_link_structure) which this approach is based on.

Код WcPaySubscriptionsPage::restructure_menu_order() WC 6.6.1

public function restructure_menu_order() {
	global $submenu;
	$wc_admin_menu           = array();
	$subscriptions_menu_item = null;

	if ( ! isset( $submenu['woocommerce'] ) ) {
		return;
	}
	foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
		$wc_admin_menu[ $key ] = $menu_item;

		// Add a placeholder element for the Subscriptions item after the Orders element. We'll replace it later.
		if ( 'edit.php?post_type=shop_order' === $menu_item[2] ) {
			$wc_admin_menu['wcpay-subscriptions'] = 'wcpay-subscriptions';
		}

		// Keep a record of the subscriptions item and remove it from its current place in the menu.
		if ( self::SUBSCRIPTION_MENU_ITEM_SLUG === $menu_item[2] ) {
			$subscriptions_menu_item = $menu_item;
			unset( $wc_admin_menu[ $key ] );
		}
	}

	// Replace the placeholder element with the subscription menu item.
	if ( isset( $wc_admin_menu['wcpay-subscriptions'] ) && $subscriptions_menu_item ) {
		$wc_admin_menu['wcpay-subscriptions'] = $subscriptions_menu_item;
		$submenu['woocommerce']               = array_values( $wc_admin_menu ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
	}
}