getdokan / dokan

Multivendor marketplace platform
https://wordpress.org/plugins/dokan-lite/
258 stars 203 forks source link

Support for WooCommerce currency switcher #429

Open UVLabs opened 6 years ago

UVLabs commented 6 years ago

The plugin adds whatever total the order was, subtracted by the commission rate to the vendor. This is ok if you're using one currency, but if you're using a currency switcher Dokan adds the total of the converted amount INSTEAD of using the base shop currency so the vendor gets the correct amount.

The plugin works as it should and still deducts the commission of off the converted amount, except that this is not the correct amount for the vendor.

Lets say Vendor A has an item on sale for $5 USD and $1 commission deduction.

Customer comes along and use their native currency which let's say converts to $2 "VSD", when customer pays vendor gets $1 VSD...which converts to $2.50 USD instead of $4USD

A simple way to get around this is to always use the shop's base currency of the order total, I'm using this plugin: https://aelia.co/shop/currency-switcher-woocommerce/

It's one of the most popular currency switchers and i think they should be support for it, Dokan just needs to adhere to the sites base currency at all times so the correct amount gets added to the vendors account. I can provide a copy of the currency switcher plugin if needed

UVLabs commented 6 years ago

@rafsuntaskin I was able to get a response from the dev and he already has a filter available that can make your plugin compatible, he's his words:

The Currency Switcher provides a filter to convert an amount from one currency to another. It can be called as follows:

$converted_amount = apply_filters('wc_aelia_cs_convert', $amount, $from_currency, $to_currency);

In the call, the parameters would be the following:

$amount: The source amount to convert.
$from_currency: The source currency (e.g. the order currency).
$to_currency: The target currency (vendor's currency).

That call will return the converted amount when the Currency Switcher is active, 
and the original amount when our plugin is not active (i.e. when the site is single-currency). 
This will allow the code to work in any case, 
without adding extra checks like "if Currency Switcher is active then XYZ". 
It's a very simple integration.

Calling the conversion filter is up to Dokan, whenever it's appropriate. 
I would say it makes sense to call it when the vendor commission is calculated,
as that's when the amount has to be determined and added to vendors' account.

This is a very popular currency switcher plugin it would be great to add support