0

I have following problem:

During checkout, my customer has to fill in his billing address (at least at the first time) to calculate VAT rate and gross price. Further calculation is done via an order processor after that. So far it works fine.

My problem is, that the cart order refresh doesn't refresh the checkout panes (like the order summary) via AJAX, when the billing country (and so perhaps the valid VAT rate, too) has changed. The user has to reload the page in the browser actively or has to submit the form to see an effect, even if the order has been refreshed (and recalculated) behind the scenes already.

  1. How can I force a cart refresh and a recalculation via my custom order processor, independent from the cart order refresh interval?
  2. How can I trigger a reload for my checkout panes (in best case via AJAX, because of better UX), so that the user sees the changes just in time?

I found out that there have been hooks for that in D7 but in D8/D9 the hooks and services seem to exist no more (e.g. commerce_cart_order_refresh() - see: How can I programmatically recalculate an order total after changing the billing country ).

1 Answer 1

1

So you want to refresh some content in the page that's not part of the checkout form? Basically, this can be done using an Ajax callback and one or more Ajax callback commands:

https://www.drupal.org/docs/drupal-apis/ajax-api/core-ajax-callback-commands

You'll need to add an Ajax callback to the country field using a form_alter(), and in this callback return the Ajax commands needed to replace the targeted content, selected by class or id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.