Negative result for minus

New Member
21 0 0

Why am I receiving negative result from this formula? Both variant's price are positive. The computation is correct but I'm getting a negative one. Eg. Should be: $869, I'm getting: $-869

 <span id="eco-bal">{{ product.variants[0].price | money_without_trailing_zeros | minus: product.variants[1].price | money_without_trailing_zeros }}</span>

 

0 Likes

Could you please provide your website URL?

Thanks & Regards
Perennial Solution

Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
https://www.perennialsolution.com/
0 Likes
New Member
21 0 0

Hi, I already was able to fix it. But I have another issue. I would like to have a certain element to be shown, only when the 2nd variant of my product is showed. How could I make that happen?

0 Likes

Certain element as in? Any product image etc. Please clarify.

Thanks & Regards
Perennial Solution

Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
https://www.perennialsolution.com/
0 Likes
New Member
21 0 0

Yes. Here's what I actually tried but it didn't work.

 

{% if product.variants[1].selected == true %}
<span>SHOW ME</span>
{% endif %}

 

 

 

 

0 Likes
Highlighted
Shopify Expert
9965 84 1469

Why are you including money_without_trailing_zeros twice? That filter will take a price, and return it as a string with currency symbol. Eg, 86900 will be converted to "$869".

 

Why it's odd to do is that you go on to attempt take a number away from a string. Your formula ends up looking like this: "$869" - 123. Expect weird results when you do things like that.

 

Not sure what your reasoning is but this will be closer to what you want.

{{ product.variants[0].price | minus: product.variants[1].price | money_without_trailing_zeros }}

 

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes