Created
April 2, 2021 00:28
-
-
Save BrianHenryIE/4427558fe70b60d1e570bef0d2bab449 to your computer and use it in GitHub Desktop.
Determine what changed the order status in WooCommerce
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
<?php | |
/** | |
* When the status is set to pending from completed, record | |
* what caused/initiated the change. | |
* | |
* @hooked woocommerce_order_status_changed | |
* | |
* @see https://www.reddit.com/r/woocommerce/comments/mi1f85/status_on_old_orders_change_from_completed_to/ | |
* @see WC_Order::status_transition() | |
* | |
* @param int $order_id | |
* @param string $status_from | |
* @param string $status_to | |
*/ | |
function check_what_set_status_to_pending( $order_id, $status_from, $status_to ) { | |
if ( 'pending' === $status_to && 'completed' === $status_from ) { | |
$url = admin_url( "post.php?post={$order_id}&action=edit" ); | |
error_log("\n\n\nOrder {$order_id} status changed from {$status_from} to {$status_to}.\n{$url}\n\n"); | |
error_log((new Exception())->getTraceAsString()); | |
error_log("\n\n"); | |
} | |
} | |
add_action( 'woocommerce_order_status_changed', 'check_what_set_status_to_pending', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment