Top WooCommerce & WordPress Plugins › Forums › Product Price by Formula for WooCommerce › Formula does not work
- Support forum for the Product Price by Formula for WooCommerce.
- This topic has 3 replies, 2 voices, and was last updated 5 years, 2 months ago by Tom Anbinder.
-
AuthorPosts
-
February 8, 2019 at 1:50 pm #99087erkitcoilMember
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?
Thank you in advance.February 8, 2019 at 2:18 pm #99088Hi,
The issue is that you can’t use
x
inside the shortcode’s attributes. Please try replacingx
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 by2.5
, then by3.5
and then by4.5
. I.e. if, for example, the original product price is5
, the final price will be5 * 2.5 * 3.5 * 4.5 = 196.88
(as5
is lower than all values, i.e lower than50
, lower than100
and also lower than150
).Hope that helps.
February 8, 2019 at 6:32 pm #99089erkitcoilMemberThank you very much for your quick and great support.
Now i’m trying to solve the problem you mentioned.
Thank you again.February 8, 2019 at 7:48 pm #99090Sure, 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 by2.5
, then you need to multiply only by1.4
, because3.5 / 2.5 = 1.4
, i.e.x * 3.5
is the same asx * 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 thecompare_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.
-
AuthorPosts
- You must be logged in to reply to this topic.