Last active
January 2, 2025 16:03
-
-
Save odessy/f93047e379f1751876560a503ce4c561 to your computer and use it in GitHub Desktop.
Pipeline 7 Alpine js buy it now button sticky add to cart
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 -%} | |
Uses the shopify permalink to generate the cart link | |
https://help.shopify.com/en/manual/products/details/cart-permalink#creating-a-cart-permalink | |
Example: | |
https://my-shop-name.myshopify.com/cart/36485954240671:1 | |
{%- endcomment -%} | |
{%- if product.selling_plan_groups.size == 0 -%} | |
<div x-data="{sectionId: '{{ section.id }}', productId: '{{ product.handle }}', ...handleClick}"> | |
<button | |
@click="handleClick" | |
class= "btn btn--primary btn--full uppercase btn--add-to-cart buy-it-now">Buy it now</button> | |
</div> | |
<script> | |
function handleClick(e) { | |
const id = document.querySelector(`[data-section-id="${this.sectionId}"] form[data-product-handle="${this.productId}"] input[name="id"]`); | |
if(id){ | |
window.location.href = `${theme.routes.cart}/${id.value}:1` | |
} | |
} | |
</script> | |
{%- endif -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment