Commit da7991ceb40 for woocommerce

commit da7991ceb409689e2b329c644488944176c0ebd0
Author: Tom Cafferkey <tjcafferkey@gmail.com>
Date:   Fri Nov 20 12:37:10 2026 +0000

    Fix order-pay fatal error for refund IDs (#71195)

    * Fix order-pay fatal error for refund IDs

    * Add changelog entry for order-pay refund fix

    * Remove resolved checkout errors from PHPStan baseline

diff --git a/plugins/woocommerce/changelog/fix-71144-order-pay-refund b/plugins/woocommerce/changelog/fix-71144-order-pay-refund
new file mode 100644
index 00000000000..ffbc28230b3
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-71144-order-pay-refund
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent a critical error when the checkout payment URL contains a refund ID.
diff --git a/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php b/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php
index 3912bbab1e4..15af3478363 100644
--- a/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php
+++ b/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php
@@ -260,7 +260,7 @@ class WC_Shortcode_Checkout {
 			$order_key = isset( $_GET['key'] ) && is_string( $_GET['key'] ) ? wc_clean( wp_unslash( $_GET['key'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only flow selectors are cleaned; order access verifies key/ownership.
 			$order     = wc_get_order( $order_id );

-			if ( $order && $order->get_id() === $order_id && hash_equals( $order->get_order_key(), $order_key ) ) {
+			if ( $order instanceof WC_Order && $order->get_id() === $order_id && hash_equals( $order->get_order_key(), $order_key ) ) {

 				if ( $order->needs_payment() ) {

diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 776a1794128..a1c11b2ab27 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -30419,18 +30419,6 @@ parameters:
 			count: 1
 			path: includes/shortcodes/class-wc-shortcode-cart.php

-		-
-			message: '#^Call to an undefined method WC_Order\|WC_Order_Refund\:\:get_order_key\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/shortcodes/class-wc-shortcode-checkout.php
-
-		-
-			message: '#^Call to an undefined method WC_Order\|WC_Order_Refund\:\:needs_payment\(\)\.$#'
-			identifier: method.notFound
-			count: 1
-			path: includes/shortcodes/class-wc-shortcode-checkout.php
-
 		-
 			message: '#^Call to an undefined method object\:\:get_stock_reduced\(\)\.$#'
 			identifier: method.notFound
diff --git a/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-checkout-test.php b/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-checkout-test.php
index 0aad69c59c1..8cbe1710ee0 100644
--- a/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-checkout-test.php
+++ b/plugins/woocommerce/tests/php/includes/shortcodes/class-wc-shortcode-checkout-test.php
@@ -187,6 +187,39 @@ class WC_Shortcode_Checkout_Test extends WC_Unit_Test_Case {
 		$this->assertStringContainsString( 'Sorry, this order is invalid and cannot be paid for.', $output );
 	}

+	/**
+	 * @testdox The order-pay endpoint should reject refund IDs without a fatal error.
+	 */
+	public function test_order_pay_rejects_refund_id(): void {
+		global $wp;
+
+		$order  = WC_Helper_Order::create_order( 0 );
+		$refund = wc_create_refund(
+			array(
+				'order_id' => $order->get_id(),
+				'amount'   => 1,
+			)
+		);
+		$this->assertInstanceOf( WC_Order_Refund::class, $refund );
+
+		wp_set_current_user( 0 );
+		$wp->query_vars['order-pay'] = $refund->get_id();
+
+		ob_start();
+		try {
+			WC_Shortcode_Checkout::output( array() );
+			$output = (string) ob_get_contents();
+		} finally {
+			ob_end_clean();
+		}
+
+		$this->assertStringContainsString(
+			'Sorry, this order is invalid and cannot be paid for.',
+			$output,
+			'Refund IDs should show the invalid-order notice.'
+		);
+	}
+
 	/**
 	 * @testdox Pay page notices should render inside the shared notices wrapper.
 	 */