Last active
January 18, 2022 12:42
-
-
Save rwkyyy/020e125d724be3d41d5ff949b4e2cd31 to your computer and use it in GitHub Desktop.
CLI close orders bulk
This file contains 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
// 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