Skip to content

Instantly share code, notes, and snippets.

@wsenjer
Created August 1, 2017 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsenjer/094a24ff3e7ff0616665c4deb92444d8 to your computer and use it in GitHub Desktop.
Save wsenjer/094a24ff3e7ff0616665c4deb92444d8 to your computer and use it in GitHub Desktop.
Change WC order status
<?php
function my_change_status_function() {
 global $wp;
if ( ! empty( $wp->query_vars['order-received'] ) ) {
$order_id  = absint( $wp->query_vars['order-received'] );
$order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( $order && $order->get_order_key() === $order_key ) {
$order->update_status('completed');
}
}
}
}
add_action( 'init', 'my_change_status_function' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment