Commit 3593b4fb73 for woocommerce
commit 3593b4fb73bb0c8316ed514051c7fda6e599948d
Author: Debayan Sutradhar <debayansutradhar3@gmail.com>
Date: Tue Jan 27 17:35:29 2026 +0530
add 'store-api' alongside 'checkout' for get_created_via comparison (#58262)
* add 'store-api' alongside 'checkout' for get_created_via comparison
* Add changefile(s) from automation for the following project(s): woocommerce
* Lint fixes
* Add docblock for woocommerce_cancel_unpaid_order filter
Adds comprehensive documentation for the filter including:
- Description of when orders are auto-cancelled
- @since 2.0.3 when filter was introduced
- @since 10.6.0 when 'store-api' was added
- Parameter documentation for the boolean and order object
* Add validation check for WC_Order instance in wc_cancel_unpaid_orders
* Update PHPStan baseline after adding WC_Order validation
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
Co-authored-by: Michael Pretty <prettyboymp@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/58262-store-api-cancel-order-fix b/plugins/woocommerce/changelog/58262-store-api-cancel-order-fix
new file mode 100644
index 0000000000..e5e29dca3f
--- /dev/null
+++ b/plugins/woocommerce/changelog/58262-store-api-cancel-order-fix
@@ -0,0 +1,4 @@
+Significance: minor
+Type: fix
+
+Fix auto-cancellation for unpaid checkout block orders
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/wc-order-functions.php b/plugins/woocommerce/includes/wc-order-functions.php
index 177c160149..792fc19326 100644
--- a/plugins/woocommerce/includes/wc-order-functions.php
+++ b/plugins/woocommerce/includes/wc-order-functions.php
@@ -1118,7 +1118,26 @@ function wc_cancel_unpaid_orders() {
foreach ( $unpaid_orders as $unpaid_order ) {
$order = wc_get_order( $unpaid_order );
- if ( apply_filters( 'woocommerce_cancel_unpaid_order', 'checkout' === $order->get_created_via(), $order ) ) {
+ if ( ! $order instanceof WC_Order ) {
+ continue;
+ }
+
+ /**
+ * Filters whether an unpaid order should be automatically cancelled.
+ *
+ * By default, only orders created via customer-facing checkout (classic checkout
+ * or checkout block) are automatically cancelled. Orders created through other
+ * means (admin, REST API, plugins) are not cancelled.
+ *
+ * @since 2.0.3
+ * @since 10.6.0 Added 'store-api' to the list of order sources that are automatically cancelled.
+ *
+ * @param bool $should_cancel Whether the unpaid order should be cancelled.
+ * Default is true for orders created via 'checkout'
+ * or 'store-api', false otherwise.
+ * @param WC_Order $order The unpaid order object.
+ */
+ if ( apply_filters( 'woocommerce_cancel_unpaid_order', in_array( $order->get_created_via(), array( 'checkout', 'store-api' ), true ), $order ) ) {
$order->update_status( OrderStatus::CANCELLED, __( 'Unpaid order cancelled - time limit reached.', 'woocommerce' ) );
}
}
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 1d12ddb055..e4265ac800 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -40167,12 +40167,6 @@ parameters:
count: 1
path: includes/wc-order-functions.php
- -
- message: '#^Cannot call method get_created_via\(\) on WC_Order\|WC_Order_Refund\|false\.$#'
- identifier: method.nonObject
- count: 1
- path: includes/wc-order-functions.php
-
-
message: '#^Cannot call method get_download_expiry\(\) on WC_Product\|false\|null\.$#'
identifier: method.nonObject
@@ -40203,12 +40197,6 @@ parameters:
count: 1
path: includes/wc-order-functions.php
- -
- message: '#^Cannot call method update_status\(\) on WC_Order\|WC_Order_Refund\|false\.$#'
- identifier: method.nonObject
- count: 1
- path: includes/wc-order-functions.php
-
-
message: '#^Function remove_filter invoked with 4 parameters, 2\-3 required\.$#'
identifier: arguments.count