Add tool to delete all products

This commit is contained in:
Rebecca Scott 2021-05-19 15:43:07 +10:00
parent af877e9f3b
commit 247f742433
4 changed files with 35 additions and 0 deletions

View File

@ -31,3 +31,4 @@ require( 'admin-notes/add-note.php' );
require( 'tools/trigger-wca-install.php' ); require( 'tools/trigger-wca-install.php' );
require( 'tools/run-wc-admin-daily.php' ); require( 'tools/run-wc-admin-daily.php' );
require( 'options/rest-api.php' ); require( 'options/rest-api.php' );
require( 'tools/delete-all-products.php');

View File

@ -0,0 +1,16 @@
<?php
register_woocommerce_admin_test_helper_rest_route(
'/tools/delete-all-products/v1',
'tools_delete_all_products'
);
function tools_delete_all_products() {
$query = new \WC_Product_Query();
$products = $query->get_products();
foreach ( $products as $product ) {
$product->delete( true );
}
return true;
}

View File

@ -34,4 +34,9 @@ export default [
description: 'Run wc_admin_daily job', description: 'Run wc_admin_daily job',
action: 'runWcAdminDailyJob', action: 'runWcAdminDailyJob',
}, },
{
command: 'Delete all products',
description: 'Delete all products',
action: 'deleteAllProducts',
},
]; ];

View File

@ -138,3 +138,16 @@ export function* runWcAdminDailyJob() {
} ); } );
} ); } );
} }
export function* deleteAllProducts() {
if ( ! confirm( 'Are you sure you want to delete all of the products?' ) ) {
return;
}
yield runCommand( 'Delete all products', function* () {
yield apiFetch( {
path: `${ API_NAMESPACE }/tools/delete-all-products/v1`,
method: 'POST',
} );
} );
}