Store API: Ensure Store API recalculates cart totals prior to running validation hooks (#49455)

* Recalc totals on checkout route before validation

* changelog
This commit is contained in:
Mike Jolley 2024-07-15 15:37:26 +01:00 committed by GitHub
parent a9de74df6f
commit b462cd58bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Ensure the Store API recalculates cart totals prior to running validation hooks.

View File

@ -188,6 +188,12 @@ class Checkout extends AbstractCartRoute {
* @return \WP_REST_Response
*/
protected function get_route_post_response( \WP_REST_Request $request ) {
/**
* Before triggering validation, ensure totals are current and in turn, things such as shipping costs are present.
* This is so plugins that validate other cart data (e.g. conditional shipping and payments) can access this data.
*/
$this->cart_controller->calculate_totals();
/**
* Validate items etc are allowed in the order before the order is processed. This will fix violations and tell
* the customer.