PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]
Botoscope is currently in early access

Support Forum

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

When switching currencies, the unit of the fee changes, but the amount remains the same.

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.

I'm encountering a problem. Due to sales region policies, I added custom code that requires additional VAT fees in some regions. However, when editing an order, I noticed that switching currencies changes the currency in the order details, but the amount doesn't change. Could you please help me identify the issue?

I purchased your Pro version plugin.

Hello

Thank you for the report. We investigated it and found some shortcomings on our side, which are now fixed.

A link to the full corrected version is in the private section of this ticket. Please update the plugin: delete the old version and install the new one. If you have any plugins that cache requests, including plugins that cache database queries, please clear those caches as well after the update.

Then run your tests and let us know whether everything works correctly or whether you notice anything else.

Also, please add your purchase code to the private section. I assume you bought the plugin through Freemius.

https://share.pluginus.net/image/i20230222134241.png
https://share.pluginus.net/image/i20230222134615.png
https://share.pluginus.net/image/i20230222134511.png

I have another question. I didn't log in to this account when I purchased your Pro plugin, so there's no record of my purchase. I'd like to know how to make my account show the purchase record.

Hello

Please check emails you used for  purchasing. What system you ised for purchasing, codecanyon or freemius?

freemius

I purchased directly from your website. Do I need to provide any proof? Since I wasn't logged into my account when I made the purchase, how can I make it show that my account has already purchased the product?

When I was testing the plugin you sent me, I encountered another problem: the currency conversion used the exchange rate set in the plugin, not the exchange rate set in my code. How can I solve this?

Hello

Let me answer both of your questions.

About the exchange rate. There are two rate related filters in the plugin and they do very different things, so it is easy to pick the wrong one.

woocs_add_custom_rate only works on the plugin settings screen, at the moment a rate is fetched from the aggregator. It does not take part in any price or order calculation. If your code uses this filter, you will see your own rate in the settings while every conversion still runs on the rate stored by the plugin. That matches exactly what you are describing.

The filter you need is woocs_currency_data_manipulation. All conversion paths read the rates through it, including the order editor in the admin area. Here is the shape of it:

add_filter( 'woocs_currency_data_manipulation', function( $currencies ) {
// Set your own rate for the currency you need.
if ( isset( $currencies['EUR'] ) ) {
$currencies['EUR']['rate'] = 1.234;
}
return $currencies;
}, 20, 1 );

Two things to keep in mind.

The priority must be higher than 1. The plugin itself hooks this filter at priority 1 to apply the rate markup option, so a callback running at priority 1 or earlier will be overwritten.

Please test on a newly created order, not on an order you switched earlier. The rate is written into the order at the moment the currency is switched, and later recalculations are made from that stored value. Orders that were already saved with the old rate will not change retroactively.

About the fee problem you originally reported. Could you please confirm explicitly whether it is now fixed in the build we sent you? We are holding the public release until we have your confirmation, so this one answer would help us a lot.

About your purchase record:

Place please actual purchase code of the plugin into the private area of this ticket:
https://share.pluginus.net/image/i20230222134241.png
https://share.pluginus.net/image/i20230222134615.png
https://share.pluginus.net/image/i20230222134511.png

I've put the code I'm using in a TXT file, which I've shared with you via a link. You can take a look.

Currently, when I test the plugin, I can see that in order management, switching the currency unit changes both the value and the currency unit specified in the code. However, the only problem is that the value isn't the one I specified.

Could you please take a look at the code and tell me where I need to change it?

Once this issue with specifying the value is resolved, I think the previous bug will be completely fixed.

Hello

If I understood you correctly, the issue was that when you edited the amount values in orders using any currency other than the base currency, the values were being reset to the base currency.

We identified the issue. It occurred when “Is multiple allowed” was set to No.

We’ve now updated a couple of functions, and everything should work correctly.

The download link is in the secret area of this ticket, please unintsall the plugin and install latest zip

I've put the code I'm using in a TXT file - looks like you forgot to click on the save button

I have now saved the plugin key and the TXT code link. You can take another look and see how to make this account show that it has purchased your plugin.

Hello

Thank you for the code, that made everything clear.

Your snippet is written correctly and it works exactly where it is supposed to work: in the cart and at checkout, on the front end. The reason it has no effect on an existing order is that woocommerce_cart_calculate_fees is a cart hook. A saved order has no cart. The fee inside it is an ordinary order line with an amount written into the database at the moment the order was placed, so when you switch the currency of that order in the admin area, the plugin takes that stored amount and converts it by the exchange rate. Your function is never called during that process, which is why you always see a converted number instead of your fixed one.

There was no way to change that from outside the plugin, so we have added one for you.

An updated build is waiting in the private section of this ticket. Please upload it over FTP, or however you normally install plugins, replacing the old version completely rather than merging folders.

The new build calls a function named woocs_order_recalculated_custom right after an order has been recalculated to another currency, if such a function exists on your site. If it does not exist, nothing happens and the plugin behaves exactly as before. This is the same approach we already use elsewhere in the plugin for site specific overrides.

So, after updating, add this to your theme functions.php next to your existing fee code:

function woocs_order_recalculated_custom($order, $new_currency, $old_currency, $old_rate) {

	$fee_name = 'EU Parcel VAT';

	$fee_amounts = array(
		'EUR' => 3.00,
		'USD' => 3.50,
		'GBP' => 2.60,
		'CAD' => 4.50,
	);

	$new_currency = strtoupper($new_currency);
	$target_amount = isset($fee_amounts[$new_currency]) ? $fee_amounts[$new_currency] : 3.00;

	$difference = 0;

	foreach ($order->get_items('fee') as $item) {

		if ($item->get_name() !== $fee_name) {
			continue;
		}

		$current_amount = floatval($item->get_total());

		if (abs($current_amount - $target_amount) < 0.0001) {
			continue;
		}

		$difference += $target_amount - $current_amount;

		$item->set_total($target_amount);
		$item->save();
	}

	if (abs($difference) > 0.0001) {
		$order->set_total(floatval($order->get_total()) + $difference);
	}

	$order->save();
}

 

Three notes on it.

The fee name in the snippet must match the name you pass to add_fee exactly, character for character. If you ever rename the fee on the front end, rename it here too.

Your fee is added as non taxable, the third argument in add_fee is false, so its tax is zero and the snippet does not need to touch it. If you later make the fee taxable, the tax part will still be converted by rate and will no longer match the amount, and the snippet will need to be extended.

The order total is adjusted by the difference so that the total stays consistent with the corrected fee line.

One thing worth raising, since it is your money and not ours. Changing the currency of an order that has already been paid means the amounts stored in the order no longer match what actually went through the payment gateway, and your reports will show the new figures rather than what was charged. The snippet does what you asked, but it does not make that safe. If you can tell us why you switch the currency on existing orders, there may be a better way to get the same result.

Please test on a copy of the site first if you can, then let us know how it goes.

This is just a functional test; in reality, the currency in order information is rarely modified. This requirement arose because the currency display was inaccurate when modifying product information in your older plugin version. However, this feature is now only needed at checkout and is no longer required when modifying order information.

I'm just curious if your plugin can recognize the code I'm currently using.

Also, can I now use this account to view my purchase history?

Hello

Thank you for clarifying, that helps. Since your question can be read in two ways, let me answer both.

If you mean"will my fee code keep working on the front end together with your plugin":

Yes, but it depends on one setting, and this is important for you.

The plugin does not read or detect your code in any way. The connection is one directional: your snippet calls get_woocommerce_currency(), and our plugin makes that function return the currency the visitor has currently selected. Your switch statement then picks the right amount and passes it to add_fee(). We never convert anything added through add_fee() on the front end.

That is true when"Is multiple allowed" is set to Yes. In that mode the plugin converts product prices only, your fee line passes through untouched, and the customer sees exactly the amount you wrote in your code: 3.50 in USD, 2.60 in GBP.

When"Is multiple allowed" is set to No, the plugin works in display only mode. In that mode it hooks the legacy WooCommerce price filter, and WooCommerce passes every amount rendered by wc_price() through that filter, including fee lines in the cart and at checkout. The result is that your fixed 3.50 USD gets multiplied by the exchange rate a second time before it is displayed. There is also a second consequence of that mode which matters more for a shop taking real payments: the order and the payment gateway stay in the shop base currency, only the displayed numbers change.

So if your goal is fixed per currency fee amounts at checkout, please set"Is multiple allowed" to Yes. With that setting your code needs no changes at all.

You can verify it in two minutes. Switch to USD on the front end, add a product to the cart, go to checkout and look at the fee line. It should read exactly 3.50 and not 3.50 multiplied by your USD rate.

If you mean"does the plugin recognise my code automatically":

No, there is no automatic detection. The plugin only looks for one specific thing, and only by name: the function woocs_order_recalculated_custom that we added in the build we sent you. If a function with that exact name exists on the site, the plugin calls it after an order has been recalculated into another currency. Nothing else in your code is looked at.

Since you now say that switching the currency of an existing order is not something you actually need, you can simply not declare that function. Leave your original fee code as it is and everything on the front end works normally. The mechanism stays in the plugin and costs nothing when the function is absent, so if the need ever comes back later, you just add the function.