Add theme .js for price change when variant change on collection

Add theme .js for price change when variant change on collection
This commit is contained in:
2025-11-07 18:05:33 +00:00
parent 0e03c6d263
commit 7569483cd0

18
assets/theme.js Normal file
View File

@@ -0,0 +1,18 @@
// .... find this line
const selectedVariant = productJson.variants.find(variant => variant.id === variantId)
// ... then paste this right below
const discountPercentage = productJson.discount_percentage || 0;
var selectedVariant_compare_at_price = selectedVariant.compare_at_price;
var selectedVariant_price = selectedVariant.price;
if(discountPercentage > 0.1){
selectedVariant_price = selectedVariant.price * (1.0 - discountPercentage);
selectedVariant_compare_at_price = selectedVariant.price;
if(selectedVariant.compare_at_price > selectedVariant_compare_at_price){
selectedVariant_compare_at_price = selectedVariant.compare_at_price;
}
}
//... replace selectedVariant.price with selectedVariant_price, and replace selectedVariant_compare_price