Optional callback that allows partner to calculate and re-calculate shipping price or to update any other data that are tied to delivery address, zip, country, etc. based on the user inputs in the Checkout3 “Invoice address” or “Delivery address” forms and update the purchase accordingly.
Callback is triggered in multiple cases:
refreshForm()
on the Checkout3 instance or by reloading the page in browser.Checkout3 makes sure the data payload for the callback is correct and relevant for the calculation of the shipping by the partner. Partner needs to process the callback.
Callback is called with a new payload (or different data from previously stored information), partner is able to use Update Items feature to update the total cost of the purchase and call refreshForm()
on the Checkout3 instance to make sure the correct information is displayed in the Checkout3 form.
Callback is called with the same payload as previously, the shipping costs doesn’t have to be updated, partner calls deliveryAddressChangedContinue()
to continue with no need to update items and refreshing the form.
To use this optional callback, partner has to pass an additional flag deliveryAddressChangedCallback
to avardaCheckoutInit
. Please refer to Showing the checkout form for additional info about Checkout 3 Form initialisation.
Callback payload is an object
with zip
and country
string properties (Value country
is in ISO country code alpha2 format – SE
, FI
, etc.) as the first parameter and checkoutInstance
as the second parameter. Below you can see a code example.
<script>
var deliveryAddressChangedCallback = function({zip, country}, checkoutInstance) {
console.log("Zip: ", zip);
console.log("Country: ", country);
...
// If Delivery address has changed
// Handle Update items
// Refresh form to display the new updated data
checkoutInstance.refreshForm();
// Delivery address is the same as stored
// Shipping price is the same as was before
// Continue
checkoutInstance.deliveryAddressChangedContinue();
}
window.avardaCheckoutInit({
...
"deliveryAddressChangedCallback": deliveryAddressChangedCallback,
...
});
</script>