From 7569483cd00345e96ef8810e8ffef09fa59e1969 Mon Sep 17 00:00:00 2001 From: soulchild Date: Fri, 7 Nov 2025 18:05:33 +0000 Subject: [PATCH] Add theme .js for price change when variant change on collection Add theme .js for price change when variant change on collection --- assets/theme.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 assets/theme.js diff --git a/assets/theme.js b/assets/theme.js new file mode 100644 index 0000000..e579e73 --- /dev/null +++ b/assets/theme.js @@ -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 \ No newline at end of file