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>
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024