Commit cf5f6839a1f for woocommerce
commit cf5f6839a1fc23d8e19181e9926a0047d282978b
Author: Md Sajal <72102985+shsajalchowdhury@users.noreply.github.com>
Date: Mon Apr 27 23:40:59 2026 +0600
Log get_order() exception to WC Logger for easier debugging (#64347)
* Log get_order() exception to WC Logger for easier debugging
When get_order() catches an exception, it currently only calls
wc_caught_exception() which logs to PHP error logs. This adds
wc_get_logger() so the exception is also visible in WooCommerce
>Status > Logs, making it easier for merchants and developers
to troubleshoot order loading issues.
Fixes #36979
* Fix translators comment to match sprintf placeholders
* Address review feedback: remove translation, add changelog
- Remove __() from log message (WC convention: don't translate log messages)
- Fix array double arrow alignment
- Add changelog entry
* Fix lint: add end try comment and simplify sprintf placeholders
* Add exception object to log context for full stack trace
diff --git a/plugins/woocommerce/changelog/fix-36979-log-get-order-exception b/plugins/woocommerce/changelog/fix-36979-log-get-order-exception
new file mode 100644
index 00000000000..ddf41d1c920
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-36979-log-get-order-exception
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Log get_order() exceptions to WC Logger for easier debugging.
diff --git a/plugins/woocommerce/includes/class-wc-order-factory.php b/plugins/woocommerce/includes/class-wc-order-factory.php
index dcce79b8913..7cf55d9a239 100644
--- a/plugins/woocommerce/includes/class-wc-order-factory.php
+++ b/plugins/woocommerce/includes/class-wc-order-factory.php
@@ -53,8 +53,20 @@ class WC_Order_Factory {
return $order;
} catch ( Exception $e ) {
wc_caught_exception( $e, __FUNCTION__, array( $order_id ) );
+ wc_get_logger()->error(
+ sprintf(
+ 'Exception caught in %s: %s',
+ __FUNCTION__,
+ $e->getMessage()
+ ),
+ array(
+ 'source' => 'get_order',
+ 'order_id' => $order_id,
+ 'exception' => $e,
+ )
+ );
return false;
- }
+ }//end try
}
/**