Add plumbing to render the "Subscription" admin menu item and page.
This commit is contained in:
parent
22575242e9
commit
b6bc8d5c95
|
@ -56,6 +56,12 @@ const WCPaymentsWelcomePage = lazy( () =>
|
|||
)
|
||||
);
|
||||
|
||||
const WCPaymentsSubscriptionsPage = lazy( () =>
|
||||
import(
|
||||
/* webpackChunkName: "wc-pay-subscriptions-page" */ '../subscriptions'
|
||||
)
|
||||
);
|
||||
|
||||
export const PAGES_FILTER = 'woocommerce_admin_pages_list';
|
||||
|
||||
export const getPages = () => {
|
||||
|
@ -215,6 +221,22 @@ export const getPages = () => {
|
|||
} );
|
||||
}
|
||||
|
||||
if ( window.wcAdminFeatures[ 'wc-pay-subscriptions-page' ] ) {
|
||||
pages.push( {
|
||||
container: WCPaymentsSubscriptionsPage,
|
||||
path: '/subscriptions',
|
||||
breadcrumbs: [
|
||||
...initialBreadcrumbs,
|
||||
__( 'Subscriptions', 'woocommerce' ),
|
||||
],
|
||||
wpOpenMenu: 'toplevel_page_woocommerce',
|
||||
navArgs: {
|
||||
id: 'woocommerce-wcpay-subscriptions',
|
||||
},
|
||||
capability: 'manage_woocommerce',
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* List of WooCommerce Admin pages.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
const SubscriptionsPage = () => {
|
||||
return <p>Hello!</p>;
|
||||
};
|
||||
|
||||
export default SubscriptionsPage;
|
|
@ -26,6 +26,7 @@ declare global {
|
|||
'transient-notices': boolean;
|
||||
'wc-pay-promotion': boolean;
|
||||
'wc-pay-welcome-page': boolean;
|
||||
'wc-pay-subscriptions-page': boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
"store-alerts": true,
|
||||
"transient-notices": true,
|
||||
"wc-pay-promotion": true,
|
||||
"wc-pay-welcome-page": true
|
||||
"wc-pay-welcome-page": true,
|
||||
"wc-pay-subscriptions-page": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
"store-alerts": true,
|
||||
"transient-notices": true,
|
||||
"wc-pay-promotion": true,
|
||||
"wc-pay-welcome-page": true
|
||||
"wc-pay-welcome-page": true,
|
||||
"wc-pay-subscriptions-page": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,6 +417,7 @@ class Features {
|
|||
'Automattic\WooCommerce\Internal\Admin\ShippingLabelBanner' => 'Automattic\WooCommerce\Admin\Features\ShippingLabelBanner',
|
||||
'Automattic\WooCommerce\Internal\Admin\ShippingLabelBannerDisplayRules' => 'Automattic\WooCommerce\Admin\Features\ShippingLabelBannerDisplayRules',
|
||||
'Automattic\WooCommerce\Internal\Admin\WcPayWelcomePage' => 'Automattic\WooCommerce\Admin\Features\WcPayWelcomePage',
|
||||
'Automattic\WooCommerce\Internal\Admin\WcPaySubscriptionsPage' => 'Automattic\WooCommerce\Admin\Features\WcPaySubscriptionsPage',
|
||||
);
|
||||
foreach ( $aliases as $new_class => $orig_class ) {
|
||||
class_alias( $new_class, $orig_class );
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Automattic\WooCommerce\Internal\Admin;
|
||||
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WooCommercePayments;
|
||||
|
||||
/**
|
||||
* Contains logic related to the WooCommerce → Subscriptions admin page.
|
||||
*/
|
||||
class WcPaySubscriptionsPage {
|
||||
|
||||
/**
|
||||
* Hook into WooCommerce.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'register_subscriptions_page' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the WooCommerce → Subscriptions admin page.
|
||||
*/
|
||||
public function register_subscriptions_page() {
|
||||
global $submenu;
|
||||
|
||||
// WC Payment must not be active.
|
||||
if ( is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! WooCommercePayments::is_supported() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$menu_data = array(
|
||||
'id' => 'woocommerce-wcpay-subscriptions',
|
||||
'title' => _x( 'Subscriptions', 'Admin menu name', 'woocommerce' ),
|
||||
'parent' => 'woocommerce',
|
||||
'path' => '/subscriptions',
|
||||
'capability' => 'manage_options',
|
||||
'nav_args' => [
|
||||
'order' => 10, // TODO: this menu item should appear below the "Orders" menu item.
|
||||
'parent' => 'woocommerce',
|
||||
],
|
||||
);
|
||||
|
||||
wc_admin_register_page( $menu_data );
|
||||
|
||||
if ( ! isset( $submenu['woocommerce'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the "1" badge.
|
||||
// TODO: remove this badge after the user has visited the "Subscriptions" page the first time.
|
||||
foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
|
||||
if ( 'wc-admin&path=/subscriptions' === $menu_item[2] ) {
|
||||
$submenu['woocommerce'][ $key ][0] .= ' <span class="wcpay-subscriptions-menu-badge awaiting-mod count-1"><span class="plugin-count">1</span></span>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue