Personalized checkout and custom promotions with Shopify Scripts
Hello Community Members,
I hope this message finds you well. We are currently facing a critical issue with our custom Buy button, which is directing users to the cart successfully and accurately adjusting the item quantity. However, we are encountering a problem where the selected variant attributes are not being reflected correctly.
Here's a more detailed description of the issue:
When a user clicks the custom Buy button, the item is successfully added to the cart, and the quantity is accurately updated. However, the problem arises when it comes to variant attributes. Even though a specific variant is chosen before clicking the Buy button, the cart displays the default variant instead of the selected one.
This issue is causing confusion among our users and impacting their shopping experience within our community. We highly value your expertise and seek your guidance to help us resolve this challenge promptly.
If you require additional information about our platform or website setup to provide a solution, please do not hesitate to reach out. Your assistance is crucial, and we sincerely appreciate your support in addressing this matter.
Thank you for your prompt attention and assistance
Solved! Go to the solution
This is an accepted solution.
@Killyss , Hope you are doing well.
Could you please share your store URL? so can check and guide your accordingly.
Hi there - what is the link to the store so we can replicate this issue, to see it in action?
Cheers.
WhiteWater Web
Hello, I'm unable to provide the link here due to privacy policies. I hope you understand. I will send you the link via DM, and you can discuss it here.
This is an accepted solution.
@Killyss , Hope you are doing well.
Could you please share your store URL? so can check and guide your accordingly.
Hello, I'm unable to provide the link here due to privacy policies. I hope you understand. I will send you the link via DM, and you can discuss it here
Thank you!, it helped solve my code problem. personally and this is your code that you presented to me
<a href="#" class="beli-sekarang-button" data-product-id="{{ product.variants.first.id }}">Beli Sekarang</a>
<script>
document.addEventListener("DOMContentLoaded", function() {
var beliSekarangButtons = document.querySelectorAll(".beli-sekarang-button");
beliSekarangButtons.forEach(function(button) {
button.addEventListener("click", function(e) {
e.preventDefault();
var productId = button.getAttribute("data-product-id");
// Lakukan penambahan produk ke keranjang di sini
fetch("/cart/add.js", {
method: "POST",
body: JSON.stringify({
quantity: 1, // Jumlah produk yang akan ditambahkan
id: productId
}),
headers: {
"Content-Type": "application/json"
}
}).then(function() {
// Redirect ke halaman keranjang
window.location.href = "/cart";
});
});
});
});
</script>
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025