Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Urgent Help Needed: Variant Mismatch Issue with Custom Buy Button Leading to Cart

Solved

Urgent Help Needed: Variant Mismatch Issue with Custom Buy Button Leading to Cart

Killyss
Excursionist
16 0 4

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

Accepted Solution (1)

webwondersco
Shopify Partner
1176 169 172

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.

Web Wonders | Shopify Partner | Connect here!
- Question answered? Mark as Accepted Solution, reply helpful? Click Like
- Hire me, if you want to design, re-design, develop a store, or make changes to the pre-built store.
- a small Coffee Tip would be greatly appreciated. :)..! Instagram

View solution in original post

Replies 5 (5)

WhiteWater_Web
Shopify Partner
462 17 42

Hi there - what is the link to the store so we can replicate this issue, to see it in action?

 

Cheers.

 

WhiteWater Web

A certified Shopify Partner and Expert, WhiteWater Web (WWW) is a premium digital solutions company specializing in advanced Shopify Dev, Usability/Design, and Online Strategy. WWW has been working with the Shopify platform since 2006.
info@whitewatersolutions.com
Killyss
Excursionist
16 0 4

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.

webwondersco
Shopify Partner
1176 169 172

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.

Web Wonders | Shopify Partner | Connect here!
- Question answered? Mark as Accepted Solution, reply helpful? Click Like
- Hire me, if you want to design, re-design, develop a store, or make changes to the pre-built store.
- a small Coffee Tip would be greatly appreciated. :)..! Instagram
Killyss
Excursionist
16 0 4

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

Killyss
Excursionist
16 0 4

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>