Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
81 stars 29 forks source link

Block Based Checkout Fails to Associate Order with Subscription #456

Closed james-allan closed 9 months ago

james-allan commented 1 year ago

Describe the bug

When using block-based checkout in WooCommerce an issue occurs where a renewal order is created during the checkout process and it is not associated with the subscription. Normally paying for a failed renewal should resume the order payment, rather than create a new one.

To Reproduce

  1. Activate the following plugins: WooCommerce, WooCommerce Subscriptions, any Gateway (eg Stripe).
  2. Create a block based checkout page.
    • New page
    • /checkout block
    • Save
    • Make note of the page URL.
  3. Make sure you have 2 shipping method options.
  4. Purchase a subscription.
  5. Create a pending renewal order for the subscription.
  6. Navigate to the subscription details page and click the "Pay" button.
  7. Proceed through the checkout process using block-based checkout.
  8. Change the chosen shipping method.
  9. Process the checkout.
  10. Observe that an order is created, but it is not associated with the subscription.

Expected Behavior

When using block-based checkout, the order created during the checkout process should be correctly associated with the subscription.

Actual Behavior

With block-based checkout enabled, the order created during checkout is not associated with the subscription.

Additional Information

Disabling block-based checkout and using the [woocommerce_checkout] shortcode resolves the issue, and the order is correctly associated with the subscription.

There are a couple of functions which are used to ensure that when a customer pays for a failed renewal order that the existing order gets resumed rather than a new order being created. For the block based checkout, there must be a gap in this.

Check the following functions:

The expectation is that when WC core determines if a new order should be created or if it should be resumed they use a cart hash system. On the standard checkout we update the cart hash right before WC makes the cart hash comparison to ensure that they match. We need to check how this works with the block checkout.