-
-
Save saadsaif97/d4f24975166743e0fad1eddf22bc29a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% 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}§ion_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> |
Author
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
}
}))
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
create a section
expected-delivery.liquidwith following content