Merge pull request #16 from woocommerce/add/tool-to-delete-all-products
Tool to delete all products
This commit is contained in:
commit
15c21a516e
|
@ -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');
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -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',
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue