Commit a775dd2650f for woocommerce
commit a775dd2650f36aa55023e3eb1c708c81f005eac6
Author: Mike Jolley <mike.jolley@me.com>
Date: Wed Oct 21 10:04:47 2026 +0100
Avoid fatal when checkout login or coupon forms render during cron (#70038)
* Prevent checkout form fatals when rendered outside frontend requests
* Add changelog entry for checkout form notice fatal fix
diff --git a/plugins/woocommerce/changelog/fix-54681-checkout-template-notice-fatal b/plugins/woocommerce/changelog/fix-54681-checkout-template-notice-fatal
new file mode 100644
index 00000000000..89a44af646c
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-54681-checkout-template-notice-fatal
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent a fatal error when a plugin renders the checkout login or coupon form outside a frontend request, such as during cron.
diff --git a/plugins/woocommerce/includes/wc-template-functions.php b/plugins/woocommerce/includes/wc-template-functions.php
index e922d0d7d8a..4892f72b244 100644
--- a/plugins/woocommerce/includes/wc-template-functions.php
+++ b/plugins/woocommerce/includes/wc-template-functions.php
@@ -2853,6 +2853,16 @@ if ( ! function_exists( 'woocommerce_checkout_login_form' ) ) {
* @return void
*/
function woocommerce_checkout_login_form() {
+ if ( ! function_exists( 'wc_print_notice' ) ) {
+ // The template calls wc_print_notice(), which is only loaded for frontend requests.
+ wc_doing_it_wrong(
+ __FUNCTION__,
+ 'Function should only be used during frontend requests.',
+ '11.4.0'
+ );
+ return;
+ }
+
wc_get_template(
'checkout/form-login.php',
array(
@@ -2966,6 +2976,16 @@ if ( ! function_exists( 'woocommerce_checkout_coupon_form' ) ) {
* @return void
*/
function woocommerce_checkout_coupon_form() {
+ if ( ! function_exists( 'wc_print_notice' ) ) {
+ // The template calls wc_print_notice(), which is only loaded for frontend requests.
+ wc_doing_it_wrong(
+ __FUNCTION__,
+ 'Function should only be used during frontend requests.',
+ '11.4.0'
+ );
+ return;
+ }
+
if ( is_user_logged_in() || WC()->checkout()->is_registration_enabled() || ! WC()->checkout()->is_registration_required() ) {
wc_get_template(
'checkout/form-coupon.php',