Skip to main content

Placing the delivery estimate with custom code (advanced)

Add the Delivery Promise (Simple or Steps) widget anywhere in a product template with HTML, for custom sections or blocks that can't hold app blocks.

Written by Trevor Reid

Most stores should add the Delivery Promise (Simple) or Delivery Promise (Steps) block from the Apps tab in the theme editor. Some themes have custom sections or blocks that can't hold app blocks, so the block can't go where you want it. For those cases you can write the widget yourself as an HTML element in your theme code.

This guide is for people who know how to edit Shopify theme code and are comfortable with HTML and CSS.

Before you start

  • Turn on the ArrivesBy app embed. In the theme editor, go to App embeds and turn on Delivery Promises. The embed loads the delivery estimate. Without it, the element shows nothing.

  • Use a product template. The estimate only loads on product pages.

What's different from the app block

The estimate itself is the same: it uses the same delivery rules and dates as the theme editor block. A few things work differently, or aren't available:

  • No theme editor settings. The element doesn't appear in the theme editor's sidebar. You set everything with HTML attributes, and to make a change you edit the code.

  • Icons are chosen by name. There's no icon picker or image upload. You name one of the built-in icons, or paste your own SVG or image (see Icons below).

  • No shipping policy toggle. You add the shipping policy link yourself with a short piece of markup (see Shipping policy link below). You write the link text yourself, so it isn't translated for you.

  • No "app embed is off" warning. When the embed is off, the theme editor block shows a reminder in the editor. Hand-written code shows nothing, so if the widget is missing, check the embed first.

  • Text you write isn't translated for you. The attribute text is used exactly as written, for every language. Dates are still formatted in the shopper's language. For a store in more than one language, put your theme's own translation keys in the attributes, for example data-heading="{{ 'products.arrives_by' | t }}".

  • Same styling options. Colors, size, spacing and alignment work the same as in the block, and so does your Custom CSS.

Choose a layout

There are two elements, one for each block:

  • <ab-promise-simple>: Simple. An icon with a heading line, for example "Arrives by Oct 3 - 5", plus optional extra lines.

  • <ab-promise-steps>: Steps. A three-step timeline of Order, Ships and Arrives, each with its own icon, label and date.

You can use both on the same page, and more than one of each.

Quick start

In the theme editor, add a Custom Liquid block where you want the estimate to show, for example inside your custom section. You can also paste the code straight into a section or snippet file in the code editor.

Then paste one of these:

<ab-promise-simple></ab-promise-simple>
<ab-promise-steps></ab-promise-steps>

Save, then check a product page in your theme preview.

  • Simple shows "Arrives by [delivery_range]", plus "Ships by [ship_range]", plus the countdown line when there's a countdown. It has no icon until you add one.

  • Steps shows the Order, Ships and Arrives steps with their dates and the standard icons. It has no extra lines unless you add them.

Full examples

Simple

<ab-promise-simple
data-icon="local_shipping"
data-heading="Arrives by <strong>[delivery_range]</strong>"
data-subtext="Order today, ships by [ship_range]"
data-urgency="Order within <strong>[countdown]</strong>"
data-show-location="true"
data-location-text="Deliver to <strong>[location]</strong>"
data-date-format="short"
data-align="left"
></ab-promise-simple>

Steps

<ab-promise-steps
data-icon-order="shopping_cart"
data-icon-ship="local_shipping"
data-icon-arrival="home"
data-label-order="Order"
data-label-ship="Ships"
data-label-arrival="Arrives"
data-urgency="Order within <strong>[countdown]</strong>"
data-show-location="true"
data-color-connector="#cccccc"
data-date-format="short"
></ab-promise-steps>

Attributes

Every attribute is optional. If you leave one out, the default in the table is used.

Attribute

Works in

What it does

Default

data-heading

Simple

The main line, shown next to the icon

Arrives by <strong>[delivery_range]</strong>

data-icon

Simple

The heading icon, by name (see Icons)

No icon

data-icon-order, data-icon-ship, data-icon-arrival

Steps

The icon for each step, by name (see Icons)

shopping_cart_checkout, local_shipping, where_to_vote

data-label-order, data-label-ship, data-label-arrival

Steps

The short label above each step's date. Plain text only, so variables don't work here. Set one to "" to show only the icon and date.

Order, Ships, Arrives

data-subtext

Both

An extra line

Simple: Ships by [ship_range]
Steps: empty

data-urgency

Both

A line for the countdown

Simple: Order within <strong>[countdown]</strong>
Steps: empty

data-show-location

Both

Set to true to show the delivery location line (Scale plan or above)

Off

data-location-text

Both

The text of the location line

Deliver to <strong>[location]</strong>

data-date-format

Both

short, medium, long, weekday-short, weekday-long, short-numeric, numeric or iso

short

data-countdown-format

Both

timer, short, medium or long

timer

data-font-size

Both

Text size in pixels, for example 16

Theme size

data-space-top, data-space-bottom

Both

Space above and below, in pixels

About one line's spacing

data-color-text

Both

Text color, for example #333333

Theme color

data-color-countdown

Both

Countdown color

Text color

data-color-bg

Both

Background color. Setting it also adds padding and rounded corners.

None

data-color-connector

Steps

Color of the line joining the steps

Theme color

data-align

Both

left, center or right

Simple: left
Steps: center

data-block-id

Both

An optional unique id. Only needed if you want a stable id for your own CSS or scripts.

Generated for you

Text and variables

  • Text attributes use the same variables as the theme editor blocks, such as [delivery_range], [ship_range], [countdown] and [location]. See Customizing the Delivery Promise Theme App Extension for the full list and which lines each one works in.

  • In the heading, subtext, urgency and location text you can use <strong>, <b>, <em>, <i>, <br> and links (<a href>). Any other HTML is removed, including images and SVGs.

  • To hide a line, set it to an empty value, for example data-subtext="". If you leave the attribute out, the default in the table shows.

  • A line that uses [countdown] hides itself when there's no countdown, for example over a weekend.

  • In Steps, the step dates are filled in for you: Order is today, Ships is the ship date or range, and Arrives is the delivery date or range. A step is left out if its date isn't available.

Delivery location

Set data-show-location="true" to show a line such as "Deliver to Beverly Hills, CA". Shoppers can click it to enter their ZIP or postal code. This needs the Scale plan or above. On other plans the line stays hidden and the rest of the widget works as normal.

Icons

Name a built-in icon with data-icon (Simple) or data-icon-order, data-icon-ship and data-icon-arrival (Steps), for example data-icon="local_shipping". These are the same icons as the theme editor's icon picker (redeem is the Gift icon):

add_shopping_cart, arrow_forward, check, check_circle, chevron_right, cottage, flight_land, home, hourglass_top, inventory_2, label_important, local_shipping, pin_drop, redeem, rocket_launch, shopping_bag, shopping_basket, shopping_cart, shopping_cart_checkout, storefront, thumb_up, warehouse, where_to_vote

  • Defaults: Simple has no icon unless you set data-icon. Steps shows shopping_cart_checkout, local_shipping and where_to_vote unless you set a name. A blank name uses the default.

  • An unknown name shows no icon and doesn't cause an error.

  • Icons take the text color. To color only the icons, add this CSS: .ab-promise-icon { color: #1a73e8; }.

Your own icon

To use your own SVG or image, put it in a <template data-ab-icon> inside the element. A template always wins over the name, and an empty template shows no icon. For Steps, use one template per step, named order, ship or arrival, and only the steps with a template are affected.

<ab-promise-simple>
<template data-ab-icon>
<img src="{{ 'truck.png' | asset_url }}" width="24" height="24" alt="">
</template>
</ab-promise-simple>
<ab-promise-steps>
<template data-ab-icon="order"><img src="{{ 'cart.svg' | asset_url }}" width="24" height="24" alt=""></template>
<template data-ab-icon="ship"></template>
</ab-promise-steps>

In the second example the Order step uses your image, the Ships step has no icon, and the Arrives step uses its default icon.

  • For a theme asset use {{ 'file-name.png' | asset_url }}. For a file under Content > Files, use {{ 'file-name.png' | file_url }}.

  • An SVG with fill="currentColor" takes the text color. You can't recolor an image with CSS.

Adding an icon before the location line

The location text doesn't accept images or SVGs, so add the icon with CSS. Put this in your theme CSS, or in a <style> tag in the same Custom Liquid block. It works for both Simple and Steps, and adds a map pin that matches the text color:

<style>
.ab-promise-location {
--ab-pin: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960'><path d='M480-480q33 0 56.5-23.5T560-560q0-33-23.5-56.5T480-640q-33 0-56.5 23.5T400-560q0 33 23.5 56.5T480-480Zm0 294q122-112 181-203.5T720-552q0-109-69.5-178.5T480-800q-101 0-170.5 69.5T240-552q0 71 59 162.5T480-186Zm0 106Q319-217 239.5-334.5T160-552q0-150 96.5-239T480-880q127 0 223.5 89T800-552q0 100-79.5 217.5T480-80Zm0-480Z'/></svg>");
display: flex;
align-items: center;
gap: 0.35em;
}
.ab-promise-location::before {
content: "";
flex: none;
width: 1.1em;
height: 1.1em;
background-color: currentColor;
-webkit-mask: var(--ab-pin) center / contain no-repeat;
mask: var(--ab-pin) center / contain no-repeat;
}
</style>
  • To color only the pin, change background-color, for example to #1a73e8.

  • To use your own image instead, replace the background-color and both mask lines with background: url("{{ 'pin.svg' | asset_url }}") center / contain no-repeat;. Liquid works here because the code is inside a Custom Liquid block or a theme file.

  • The same CSS also works with the theme editor blocks.

Shipping policy link (optional)

To add a link that opens your shipping policy in a popup, add a <template data-ab-policy> inside the element. It works in both Simple and Steps. It needs a shipping policy set in your Shopify settings. If you use more than one widget on a page, give each popup its own id.

{%- if shop.shipping_policy != blank -%}
<template data-ab-policy>
<button class="ab-promise-policy-trigger" type="button" popovertarget="ab-shipping-policy" popovertargetaction="toggle">Shipping policy</button>
<div popover class="ab-promise-policy-popover" id="ab-shipping-policy">
<div class="ab-promise-popover-header">
<span class="ab-promise-popover-title">Shipping policy</span>
<button type="button" class="ab-promise-popover-close" aria-label="Close" popovertarget="ab-shipping-policy" popovertargetaction="hide">&times;</button>
</div>
<div class="ab-promise-policy-content">{{ shop.shipping_policy }}</div>
</div>
</template>
{%- endif -%}

Styling with CSS

The widgets use the same classes as the theme editor blocks, so you can target them in your theme CSS.

Both layouts

  • .ab-promise-card: the whole widget. It also gets .ab-promise-boxed when a background color is set.

  • .ab-promise-icon: any icon.

  • .ab-promise-subtext: the subtext line. The urgency line also has .ab-promise-urgency.

  • .ab-promise-location: the location line. .ab-promise-location-trigger is the clickable location.

  • .ab-promise-policy-trigger: the shipping policy link.

Simple

  • .ab-promise-heading: the icon and heading row.

  • .ab-promise-title: the heading text.

Steps

  • .ab-promise-steps-card: the whole widget.

  • .ab-promise-steps: the list of steps.

  • .ab-promise-step: each step. They also have .ab-promise-step-order, .ab-promise-step-ship and .ab-promise-step-arrival.

  • .ab-promise-step-icon, .ab-promise-step-label and .ab-promise-step-date: the parts of a step.

To change the corner radius or padding of a boxed widget, set --ab-promise-radius and --ab-promise-padding on the element. See Custom CSS for more examples.

If nothing shows

  • Check that the Delivery Promises app embed is on in the theme you're editing.

  • Check that you're on a product page. The widget stays hidden on other pages.

  • Check that a delivery rule applies to the product and doesn't hide the estimate. See Troubleshooting delivery estimates.

  • Check that the tag is exactly <ab-promise-simple> or <ab-promise-steps> and has a closing tag.

Still stuck? Message us from the app and include the page where you added the code.

Did this answer your question?