Skip to content

Instantly share code, notes, and snippets.

@BrianHenryIE
Created November 15, 2020 22:09
Show Gist options
  • Save BrianHenryIE/1d516bda861a2f3bb9c94e3a6c1ac795 to your computer and use it in GitHub Desktop.
Save BrianHenryIE/1d516bda861a2f3bb9c94e3a6c1ac795 to your computer and use it in GitHub Desktop.
Log WooCommerce order status changes with debug backtrace to determine what caused it.
<?php
/**
* When the status is set to processing, record what caused/initiated the change.
*
* Need in `wp-config.php`:
* define('WP_DEBUG', true);
* define('WP_DEBUG_LOG', true);
*
* @hooked woocommerce_order_status_changed
*
* @see WC_Order::status_transition()
*
* @param int $order_id
* @param string $status_from Un-prefixed WooCommerce order status.
* @param string $status_to
*/
function log_what_set_status_to_processing( $order_id, $status_from, $status_to ) {
if ( 'processing' === $status_to ) {
$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', 'log_what_set_status_to_processing', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment