Skip to content

Instantly share code, notes, and snippets.

@saadsaif97
Created June 17, 2025 07:38
Show Gist options
  • Select an option

  • Save saadsaif97/d4f24975166743e0fad1eddf22bc29a6 to your computer and use it in GitHub Desktop.

Select an option

Save saadsaif97/d4f24975166743e0fad1eddf22bc29a6 to your computer and use it in GitHub Desktop.
{% comment %} add this code in the main-product.liquid {% endcomment %}
<script>
const productUrl = `{{ product.url }}`;
const sectionId = "expected-delivery";
document.addEventListener("variant:updated", (e) => {
const url = `${productUrl}?variant=${e.detail.variantId}&section_id=${sectionId}`
console.log(url)
fetch(url)
.then((response) => response.text())
.then((responseText) => {
const html = new DOMParser().parseFromString(responseText, 'text/html');
const updateDeliveryText = html.getElementById("shopify-section-expected-delivery").innerHTML;
document.getElementById("delivery-text").innerHTML = updateDeliveryText;
})
.catch((e) => {
console.error(e);
})
})
</script>
@saadsaif97

Copy link
Copy Markdown
Author

create a section expected-delivery.liquid with following content

<p>
  Delivery expected in: {{ product.selected_or_first_available_variant.metafields.custom.delivery_time }}
</p>

@saadsaif97

Copy link
Copy Markdown
Author

in product-info.js search for callback(html); and add following code under that line:

const variantId = html.querySelector("product-form [name='id']").value;
document.dispatchEvent(new CustomEvent("variant:updated", {
  detail: {
    variantId
  }
}))

@saadsaif97

Copy link
Copy Markdown
Author

then you need to render the information in main-product.liquid after the line {%- when 'buy_buttons' -%}

<div id="delivery-text">
  Delivery expected in: {{ product.selected_or_first_available_variant.metafields.custom.delivery_time }}
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment