Last active
June 2, 2020 15:57
-
-
Save vanbo/850025ed4b531620c706c7685dd11fb2 to your computer and use it in GitHub Desktop.
Complete the order from a link to the Edit order screen
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
add_action( 'admin_init', 'vanbo_update_order_status', 10 ); | |
function vanbo_update_order_status() { | |
// We need the 'post', 'action' = edit, and 'prefix-change-status' to be set. | |
// If even one is not set, bail | |
if ( ! isset( $_GET['post'] ) | |
|| ( ! isset( $_GET['action'] ) || 'edit' != $_GET['action'] ) | |
|| ! isset( $_GET['prefix-change-status'] ) ) { | |
return; | |
} | |
// Get the order and the status name | |
$order = wc_get_order( (int) wc_clean( $_GET['post'] ) ); | |
$status = wc_clean( $_GET['prefix-change-status'] ) ? wc_clean( $_GET['prefix-change-status'] ) : 'completed'; | |
// Set the order status | |
$order->set_status( $status ); | |
$order->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment