diff --git a/product-card.liquid b/product-card.liquid index 841b078..0d93063 100644 --- a/product-card.liquid +++ b/product-card.liquid @@ -123,7 +123,19 @@ Supported variables {%- if show_prices and product.template_suffix != 'quote' -%}
- {{ product.selected_or_first_available_variant.price | money }} + {% assign v = product.selected_or_first_available_variant %} + {% assign variant_price = product.selected_or_first_available_variant.price %} + {% if v.metafields.app--168074346497.discount_type.value != nil and v.metafields.app--168074346497.discount_type.value != "fixed" and product.metafields.app--168074346497.discount_percentage.value > 0.01 %} + {% assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value %} + + {% if v.metafields.app--168074346497.discount_percentage.value > 0.01 %} + {% assign deducted_percentage = 1.0 | minus: v.metafields.app--168074346497.discount_percentage.value %} + {% endif %} + + {% assign variant_price = v.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil %} + {% endif %} + + {{ variant_price | money }}
{%- endif -%} @@ -277,11 +289,16 @@ Supported variables // Update hidden input with the correct variant ID $('#selected-variant-id-{{ product.id }}').val(selectedVariant.id); + {% assign deducted_percentage = 1.0 %} + {% if product.metafields.app--168074346497.discount_percentage.value > 0.01 %} + {% assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value %} + {% endif %} + // Update displayed price let locale = Shopify.locale; let currency = Shopify.currency.active; let country = Shopify.country; - let amount = new Intl.NumberFormat(`${locale}-${country}`, { style: "currency", currency: currency }).format(selectedVariant.price / 100 ); + let amount = new Intl.NumberFormat(`${locale}-${country}`, { style: "currency", currency: currency }).format(selectedVariant.price / 100 * {{ deducted_percentage }}); $(this).find('.product-price').text(amount); } else { console.log('No matching variant found for the selected options.');