# Formula does not work

Viewing 4 posts - 1 through 4 (of 4 total)
• Author
Posts
• #99087
erkitcoil
Member

Hello.
I’m trying using this formula to change prices:

```x[if_value value="x" compare_operator="less" compare_to_value="50"]*2.5[/if_value]
[if_value value="x" compare_operator="less" compare_to_value="100"]*3.5[/if_value]
[if_value value="x" compare_operator="less" compare_to_value="150"]*4.5[/if_value]```

For some reason it does not work.
Do you have any idea, why?

#99088
Tom Anbinder
Moderator
Plugin Support

Hi,

The issue is that you can’t use `x` inside the shortcode’s attributes. Please try replacing `x` with `{product_meta key='_price'}`, i.e.:

```x[if_value value="{product_meta key='_price'}" compare_operator="less" compare_to_value="50"]*2.5[/if_value]
[if_value value="{product_meta key='_price'}" compare_operator="less" compare_to_value="100"]*3.5[/if_value]
[if_value value="{product_meta key='_price'}" compare_operator="less" compare_to_value="150"]*4.5[/if_value]```

* Please note that in your example if the original price is lower than `50` it will be multiplied by `2.5`, then by `3.5` and then by `4.5`. I.e. if, for example, the original product price is `5`, the final price will be `5 * 2.5 * 3.5 * 4.5 = 196.88` (as `5` is lower than all values, i.e lower than `50`, lower than `100` and also lower than `150`).

Hope that helps.

#99089
erkitcoil
Member

Thank you very much for your quick and great support.
Now i’m trying to solve the problem you mentioned.
Thank you again.

#99090
Tom Anbinder
Moderator
Plugin Support

Sure, no problem, happy to help 🙂

Regarding your task – if understood it correctly – one solution would be to re-calculate multipliers. I.e. if you need to multiply the price by `3.5`, but it was already multiplied by `2.5`, then you need to multiply only by `1.4`, because `3.5 / 2.5 = 1.4`, i.e. `x * 3.5` is the same as `x * 2.5 * 1.4`. Hope you get the idea. So your formula would look like this:

```x[if_value value="{product_meta key='_price'}" compare_operator="less" compare_to_value="50"]*2.5[/if_value]
[if_value value="{product_meta key='_price'}" compare_operator="less" compare_to_value="100"]*1.4[/if_value]
[if_value value="{product_meta key='_price'}" compare_operator="less" compare_to_value="150"]*1.2857[/if_value]```

Now after your question, I’m thinking that I should add new `between` value to the `compare_operator` attribute in the `[if_value]` the shortcode, so it could be used like that:

`x[if_value value="{product_meta key='_price'}" compare_operator="between" compare_to_value="50,100"]*2.5[/if_value]`

I.e. `compare_to_value` attribute would be set as comma separated values. Will be adding that in next plugin version.

Hope that helps.

P.S. If you like the plugin, please consider leaving us a rating.

Viewing 4 posts - 1 through 4 (of 4 total)
• The forum ‘Product Price by Formula for WooCommerce’ is closed to new topics and replies.