Merge pull request #16 from woocommerce/add/tool-to-delete-all-products

Tool to delete all products
This commit is contained in:
Bec Scott 2021-06-08 17:16:45 +10:00 committed by GitHub
commit 15c21a516e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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/run-wc-admin-daily.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',
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',
} );
} );
}