From e3a179ff1ca36b0a854ba2afad811fe3cfbc3b4b Mon Sep 17 00:00:00 2001 From: boblinthorst Date: Thu, 17 Aug 2023 12:26:58 +0200 Subject: [PATCH 1/3] Prevent non-WC_Orders on the order received page To ensure they have an implementation of the get_order_key function. Visits to the order_received page with the id of a refund result in a fatal error. --- .../changelog/BL-prevent-non-orders-on-order-received-page | 4 ++++ .../includes/shortcodes/class-wc-shortcode-checkout.php | 2 +- plugins/woocommerce/includes/wc-cart-functions.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page diff --git a/plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page b/plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page new file mode 100644 index 0000000000000..d5fa00efe6783 --- /dev/null +++ b/plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +No longer fatals on order-received page when provided with the id of a refund diff --git a/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php b/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php index 1915c580ffc03..40b94331095d6 100644 --- a/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php +++ b/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php @@ -271,7 +271,7 @@ private static function order_received( $order_id = 0 ) { if ( $order_id > 0 ) { $order = wc_get_order( $order_id ); - if ( ! $order || ! hash_equals( $order->get_order_key(), $order_key ) ) { + if ( ( ! $order instanceof WC_Order ) || ! hash_equals( $order->get_order_key(), $order_key ) ) { $order = false; } } diff --git a/plugins/woocommerce/includes/wc-cart-functions.php b/plugins/woocommerce/includes/wc-cart-functions.php index 94fba81e7fd9b..cb696746e637f 100644 --- a/plugins/woocommerce/includes/wc-cart-functions.php +++ b/plugins/woocommerce/includes/wc-cart-functions.php @@ -176,7 +176,7 @@ function wc_clear_cart_after_payment() { if ( $order_id > 0 ) { $order = wc_get_order( $order_id ); - if ( $order && hash_equals( $order->get_order_key(), $order_key ) ) { + if ( $order instanceof WC_Order && hash_equals( $order->get_order_key(), $order_key ) ) { WC()->cart->empty_cart(); } } From 88844182edf444c87259484b8585823ad3cf867b Mon Sep 17 00:00:00 2001 From: boblinthorst Date: Fri, 25 Aug 2023 14:17:44 +0200 Subject: [PATCH 2/3] Also check for instanceof WC_Order here to be consistent with the implementation above --- plugins/woocommerce/includes/wc-cart-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/includes/wc-cart-functions.php b/plugins/woocommerce/includes/wc-cart-functions.php index cb696746e637f..9c883491d40d1 100644 --- a/plugins/woocommerce/includes/wc-cart-functions.php +++ b/plugins/woocommerce/includes/wc-cart-functions.php @@ -185,7 +185,7 @@ function wc_clear_cart_after_payment() { if ( WC()->session->order_awaiting_payment > 0 ) { $order = wc_get_order( WC()->session->order_awaiting_payment ); - if ( $order && $order->get_id() > 0 ) { + if ( $order instanceof WC_Order && $order->get_id() > 0 ) { // If the order has not failed, or is not pending, the order must have gone through. if ( ! $order->has_status( array( 'failed', 'pending', 'cancelled' ) ) ) { WC()->cart->empty_cart(); From 413e569ccd22d859a8607df98be2a9b5b361be91 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 25 Aug 2023 23:08:02 +0000 Subject: [PATCH 3/3] Add changefile(s) from automation for the following project(s): woocommerce --- .../changelog/BL-prevent-non-orders-on-order-received-page | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page b/plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page index d5fa00efe6783..7e40a6cee1535 100644 --- a/plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page +++ b/plugins/woocommerce/changelog/BL-prevent-non-orders-on-order-received-page @@ -1,4 +1,4 @@ -Significance: patch +Significance: minor Type: fix -No longer fatals on order-received page when provided with the id of a refund +Avoid a fatal error on the order received page if the order ID is not for a valid order.