Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Created February 18, 2025 08:53
Show Gist options
  • Save kasparsd/59fa1ba66a2243223de427c3f2072ac4 to your computer and use it in GitHub Desktop.
Save kasparsd/59fa1ba66a2243223de427c3f2072ac4 to your computer and use it in GitHub Desktop.
<?php
namespace YourVendor\WooCommerce_CLI;
use WP_CLI;
use WooCommerce;
function anon_orders( $args, $assoc_args ) {
$order_ids = wc_get_orders(
[
'limit' => -1,
'return' => 'ids',
]
);
foreach ( $order_ids as $id ) {
$order = wc_get_order( $id );
if ( $order ) {
do_action( 'woocommerce_remove_order_personal_data', $order );
WP_CLI::success( sprintf( 'Anonymized order #%d', $id ) );
}
}
}
add_action(
'plugins_loaded',
function () {
if ( class_exists( WP_CLI::class ) && defined( 'WP_CLI' ) && class_exists( WooCommerce::class ) ) {
WP_CLI::add_command( 'wc anon_orders', __NAMESPACE__ . '\anon_orders' );
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment