Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Last active January 18, 2022 12:42
Show Gist options
  • Save rwkyyy/020e125d724be3d41d5ff949b4e2cd31 to your computer and use it in GitHub Desktop.
Save rwkyyy/020e125d724be3d41d5ff949b4e2cd31 to your computer and use it in GitHub Desktop.
CLI close orders bulk
// CLI init & close BULK
function orders_close_query() {
$args = array(
'post_type' => 'shop_order',
'posts_per_page' => -1,
'post_status' => 'wc-shipped',
// 'order_by' => 'publish_date',
// 'order' => 'ASC'
);
$orderList = get_posts( $args );
foreach ( $orderList as $orderPost ) {
$order = new WC_Order( $orderPost->ID );
$order->update_status( 'completed' );
}
WP_CLI::success( 'Done!' );
}
function urs_register_cli_commands() {
WP_CLI::add_command( 'close_orders', 'orders_close_query' );
}
add_action( 'cli_init', 'urs_register_cli_commands' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment