PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Non-default currency Woo hook: woocommerce_before_calculate_totals - set_price not working

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi Team,

I have a custom snippet which is doing calculations based on the product and user-related ACF repeater fields.
The user have discount percentages assigned to custom taxonomy and if a product with that taxonomy term is in the cart I need to create a new price.

Everything works with the base/default currency but as soon as I change the currency to other the set_price function is not working.

I have tried also the 'woocs_raw_woocommerce_price' filter too, but with it I don't have access to cart item data.

So my question is how can I override the price in this case?
We are using fixed prices because it's a pricelist for products which is changing yearly only at the company.

At the product I also have more prices for the default currency and for EUR currency too. So I need to check those too.
For example here the logic is.
If there is a Szerződéses akciós ár (€) set I need to set that price.
If the Szerződéses akciós ár (€)  is not set but the Sale price EUR yes I need to use that price, if there is a user-related percentage discount I need to calculate with that.
If no Szerződéses akciós ár (€) and no Sale Price EUR is set I need to use Regular price, if user-related percentage discount is set I need to calculate with that.

The logic is working correctly with the HUF price which is the default/base currency.

But even if I add only a basic code to set_price it is not working.

Can you please help us to point in to the right direction?
How can we alter the EUR prices in cart and checkout?

Thank you.

Hello

woocs_raw_woocommerce_price - This hook works for all conversions and for fixed currencies.

to get a fixed price you just need to call the standard get price function

OR -
global $WOOCS;
$fixed_price = $WOOCS->_get_product_fixed_price(WC_Product $product, 'single', $price, $precision);

Hi,

Sorry but I don't just need to get fixed prices. I need to do discount calculations with them and update the price in the cart/checkout. I also have a 3rd price which I need to use.

My code is working with the default HUF currency, but with EUR prices I cant set the price in the cart/checkout with the set_price Woo function.

Can you please check the screencast I have attached to the Private data?

With this filter I dont have access to cart item data, so I can't do calculations and use different caluclations for different products. Because this hook can change things only by the price woocs_raw_woocommerce_price.

Hello

cart item data - this is a product object

For this reason, a fixed price overrides your price(set_price)

Hi,

And is there a way to override, disable this behavior, so I can use set_price?
Or that is not possible with your plugin?

Hello

No. Because this function is used before the hook.

Ok,
So no other solution is possible where I can edit the EUR Fixed price with my own calculations in the Cart and Checkout?
I need to have the product ID so the woocs_raw_woocommerce_price filter is not a solution for me right now.

Hello

You can try this hook - https://currency-switcher.com/hook/woocs_fixed_raw_woocommerce_price