Created
February 18, 2025 08:53
-
-
Save kasparsd/59fa1ba66a2243223de427c3f2072ac4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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