Shipping estimate
A form where the visitor types a country and a postal code and reads the delivery options Shopify has for that address, with their prices, before the checkout.
With a shipping estimate form, a visitor types a country and a postal code and sees the delivery options Shopify has for that address, with their prices, before going to the checkout. Smootify puts the address on the visitor’s cart and asks Shopify for its rates. The visitor picks one, and the cart total follows. The checkout then opens with that country, postal code and option already filled in. The cart is the usual place for it, under the lines and above the total.
Note
It works on every Smootify plan, the free one too, with no add-on to turn on. The options and their prices are the shipping rates you set in Shopify (Settings › Shipping and delivery).
1. Add the form
Write a shipping-estimate element, and put a <form> inside it. It can go anywhere, inside the cart too: the cart never takes this form as its own.
Inside the form, add these fields. Smootify reads their name, in any case:
- Country: a
<select name="country">. Smootify also readscountry_code,paeseandnazione. Leave it with only its placeholder option: Smootify fills it with the countries of your Shopify markets and chooses the cart’s country, or the market’s when the visitor has no cart yet. Without a country field, or with none chosen, that country is used. - Postal code: an input named
zip. Smootify also readszip_code,postal_code,postcodeandcap. - Province, optional: an input or select named
province. Smootify also readsstate,regionandprovincia. Add it for countries where Shopify’s rates change by province or state. - a submit button.
2. Show the options
Under the form, add one element with shipping-option="item". Smootify copies it once per delivery option. Inside it:
shipping-option="title": the name of the rate in Shopify, such as “Standard”.shipping-option="price": its price, in the site’s price format. A rate at 0 shows “Free”, or the text you write indata-free-textonshipping-estimate, such asdata-free-text="Gratis".shipping-option="description": the rate’s description, hidden when the rate has none.
The three are optional: use only the ones your design needs.
<shipping-estimate data-error-no-options="No delivery options for this address" data-free-text="Free">
<form>
<select name="country"><option value="">Country</option></select>
<input name="zip" placeholder="Postal code">
<input type="submit" value="Estimate">
</form>
<div form-fail hidden>No delivery options for this address</div>
<div shipping-option="item">
<div shipping-option="title">Standard</div>
<div shipping-option="description">3–5 business days</div>
<div shipping-option="price">€0.00</div>
</div>
</shipping-estimate>The option in the cart’s total gets the class is-selected: style it as the chosen one. A click on another option selects it, and the cart total and cart="shipping" follow (see Build the cart).
The form stays visible after the estimate, so the visitor can try another address: there is no [form-done] block to write.
3. States and the error
Smootify puts these classes on shipping-estimate:
is-loadingwhile it asks Shopify;is-estimatedwhen the options are shown;no-optionswhen Shopify has no option for that address.
With no-options, the [form-fail] block shows. Smootify writes “No delivery options for this address” in it, unless you write your own in the attribute data-error-no-options on shipping-estimate. Use it to write the message in your site’s language.
How it follows the cart
- The options follow the cart. Adding, removing or changing a line asks Shopify again, so a free shipping threshold shows as soon as the cart reaches it.
- An address already on the cart fills the form and shows its options when the page loads: one the visitor typed before, or a logged-in customer’s.
- The checkout starts from the estimate. It opens with the country, the postal code and the option the visitor chose.
- An empty cart asks nothing. Shopify has rates only for lines that ship.
- Delivery rules apply at the checkout. The Smootify app’s delivery rules rename or hide rates in the checkout only. The estimate shows Shopify’s rates before those rules.
Before you publish
Check these first
- No country in the select. The select has options of its own besides the placeholder. Leave only the placeholder, and Smootify fills it with your markets’ countries.
- “No delivery options for this address” for an address you ship to. Check the shipping zones in Shopify (Settings › Shipping and delivery): the country or the postal code is not in a zone of the products’ shipping profile.
- Nothing happens on submit. The cart is empty: add a product first.
- A rate shows in the estimate and not in the checkout, or with another name. A delivery rule changes it at the checkout.
- The error message is in English. Write your own in
data-error-no-options.