-
Notifications
You must be signed in to change notification settings - Fork 5
How To
Moon edited this page Aug 23, 2023
·
9 revisions
To add a new WC React page, you need to create a new admin menu, develop a new React component, and then register the component to a specific path
Create a new PHP file and add a new admin menu
Example: https://github.com/Automattic/wc-calypso-bridge/commit/8fe7016ac0a484831d40c4ebf51d2aded064e40c
wc_admin_register_page(
array(
'id' => 'woocommerce-wccom-helloworld',
'title' => __('Hello World', 'wc-calyso-bridge'),
'nav_args' => array(
'title' => __( 'Hello World', 'wc-calyso-bridge' ),
),
'path'=> '/hello-world',
'position' => 65,
'icon'=>'dashicons-admin-plugins',
'capability' => 'manage_options',
)
);
Create a new React component in src/
directory
Example: https://github.com/Automattic/wc-calypso-bridge/commit/b9fdba461b0ddf1968dce03d83606ce4ee8bcebf
const HelloWorld = () => {
return (
<div>
<h1>Hello World</h1>
</div>
);
};
export default HelloWorld;
Example: https://github.com/Automattic/wc-calypso-bridge/commit/06d5a8a1f269eb37075c03c98320e8b36c439aa2
- Open src/index.js
- Define a lazy load for HelloWorld component.
const HelloWorld = lazy( () =>
import( /* webpackChunkName: "hello-world" */ './hello-world' )
);
- Add
woocommerce_admin_pages_list
hook callback. Append the following code snippet to register a React page.
pages.push( {
container: HelloWorld,
path: '/hello-world',
breadcrumbs: [ 'Hello', 'World' ],
navArgs: {
id: 'hello-world',
},
capability: 'manage_woocommerce',
} );
- Refresh wp-admin and test the changes.