A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
Go to file
Rebecca Scott e2f20bd546 Tool to trigger WCA install 2021-03-04 10:58:03 +10:00
api Tool to trigger WCA install 2021-03-04 10:58:03 +10:00
src Tool to trigger WCA install 2021-03-04 10:58:03 +10:00
.eslintrc.js set up empty plugin 2021-02-22 12:16:59 +10:00
.gitignore Add to the tools menu 2021-02-23 15:30:49 +10:00
.prettierrc.json set up empty plugin 2021-02-22 12:16:59 +10:00
README.md hooks to add tabs and tools 2021-03-01 16:38:26 +10:00
package-lock.json finish up delete all notes feature 2021-03-01 13:57:53 +10:00
package.json hooks to add tabs and tools 2021-03-01 16:38:26 +10:00
plugin.php finish up delete all notes feature 2021-03-01 13:57:53 +10:00
webpack.config.js set up empty plugin 2021-02-22 12:16:59 +10:00
woocommerce-admin-test-helper.php Add admin notes helper, stuck on using @woocommerce/data 2021-02-28 19:02:27 +10:00

README.md

WooCommerce Admin Test Helper

A plugin that makes it easier to test the WooCommerce Admin plugin.

Development

To get started, run the following commands:

npm install
npm start

See wp-scripts for more usage information.

Extending

There are two client-side filters available if you want to extend the test helper with your own plugin's test setup code.

This example adds a new tab:

import { addFilter } from '@wordpress/hooks';

const SuperSekret = () => (
	<>
		<h2>Super sekret</h2>
		<p>This section contains super sekret tools.</p>
		<NewTool/>
	</>
);
addFilter(
	'woocommerce_admin_test_helper_tabs',
	'wath',
	( tabs ) => [
		...tabs,
		{
			name: 'super-sekret',
			title: 'Super sekret',
			content: <SuperSekret/>,
		}
	]
);

This example adds a new tool to the existing Options tab:

import { addFilter } from '@wordpress/hooks';

const NewTool = () => (
	<>
		<strong>New tool</strong>
		<p>Description</p>
		<button>Execute</button>
	</>
);
addFilter(
	'woocommerce_admin_test_helper_tab_options',
	'wath',
	( entries ) => [
		...entries,
		<NewTool/>
	]
);

Register a REST API endpoint to perform server-side actions in the usual way:

add_action( 'rest_api_init', function() {
    register_rest_route(
        'your-plugin/v1',
        '/area/action',
        array(
            'methods' => 'POST',
            'callback' => 'your_plugin_area_action',
            'permission_callback' => function( $request ) {
                if ( ! wc_rest_check_manager_permissions( 'settings', 'edit ) ) {
                    return new \WP_Error(
                        'woocommerce_rest_cannot_edit',
                        __( 'Sorry, you cannot perform this action', 'your-plugin' )
                    );
                }
                return true;
            }
        )
    );
} );

function your_plugin_area_action() {
    return [];
}

This would be used on the client like this:

import apiFetch from '@wordpress/api-fetch';
...
const response = await apiFetch( {
    path: '/your-plugin/v1/area/action',
    method: 'POST',
} );