Currency is switching on its own
-
Hello, I’ve been using WOOCS for a while, and it is a great plugin, so kudos for the great work.
Occasionally, I face an issue, which I cannot reproduce! As I am not aware of why it happened in the first place, I will tell you a little bit about my setup so you can get the full picture:
I’m using Terawallet (a plugins of which I hope one day will be integrated with WOOCS), I setup two currencies, USD and TRY, I have added a user meta to each of my clients, they either buy in USD or in TRY, they cannot choose, or switch currencies, because their balances are either in USD or TRY.
This is the code I use to force currency setting:
add_filter('wp_head',function(){ global $WOOCS; $currency = get_user_meta( get_current_user_id(), 'currency', true); if($currency != ''){ $WOOCS->set_currency($currency); }elseif(!is_user_logged_in()){ $WOOCS->set_currency('TRY'); }else{ $WOOCS->set_currency('USD'); } });
I then started facing an issue where orders that are supposed to be in TRY were placed in USD! So I added this code to double check to prevent this from happening:
function action_woocommerce_checkout_create_order( $order, $data ) { global $WOOCS; $currency = get_user_meta( get_current_user_id(), 'currency', true); if($WOOCS->current_currency != $currency){ // Display our error message wc_add_notice( 'An error occurred, please check your cart items and try again', 'error' ); } }; // add the action add_action( 'woocommerce_checkout_create_order', 'action_woocommerce_checkout_create_order', 10, 2 );
I’m assuming wc_add_notice with the type error, should interrupt checkout right? Even though I did all that, I still have orders that are placed in the wrong currency! Which either costs me money, or makes me look like fraud to some of the clients
Take a look at this order for example! The user has USD in his meta, and the order was placed in TRY, and the total was calculated in TRY so the amount deducted from his USD wallet was 7 times greater than what he should pay
https://drive.google.com/file/d/1DZak4W7gMBJbUz4-nKGtREhnG1niCpsj/view?usp=sharing
Notice how it says currency rate is 1 When it should say something else! The currency rate was 1, but order total was in fact multiplied by the currency rate.
So bottom line is, what can I do, to absolutely and surely, set currency and not allow it to ever change for the life of the request
Thanks
- The topic ‘Currency is switching on its own’ is closed to new replies.