Created with Sketch.
Created with Sketch.

Delivery address changed

It is optional callback to make checkout work to your needs. This callback is called every time in Checkout3 is added/changed or removed delivery address – also when customer fill invoice address and have no delivery address. Callback gets zip (string) value as first argument and checkoutInstance as second parameter. Below you can see code example. When shipping price is changed, you can handle this information and use update items feature. Where shipping price is same as before, call deliveryAddressChangedContinue on checkoutInstance, which you get as second parameter in provided callback, to allow customer to continue in Checkout form (Checkout form waits for refreshForm or deliveryAddressChangedContinue action).

<script>
  var deliveryAddressChangedCallback = function(zip, checkoutInstance) {
    console.log("Zip: ", zip);

    ...

    // Refresh form when there is different price for new deliveryAddress, etc.
checkoutInstance.refreshForm();

    // Or when shipping price is same as was before
    checkoutInstance.deliveryAddressChangedContinue();

    // In both cases, you can call:
    checkoutInstance.refreshForm();
    // and Checkout form will refresh, and customer can continue
  }

  window.avardaCheckoutInit({
    ...
    "deliveryAddressChangedCallback": deliveryAddressChangedCallback,
    ...
  });
</script>