• Resolved alkateb

    (@alkateb)


    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support mediawebster

    (@mediawebster)

    Hello

    What payment system do you use?
    Perhaps this payment system only accepts TRY

    • This reply was modified 4 years, 6 months ago by mediawebster.
    Thread Starter alkateb

    (@alkateb)

    I’m using Terawallet, as mentioned above in the post, and no, this system does not support multiple currencies and it surely isn’t an issue with the payment system, because I’m not facing this issue with all the orders.

    To make my question clearer, if I want to force a user to use a specific currency, am I completely covered when using set_currency, with the two hooks I’m using above?

    wp_head AND woocommerce_checkout_create_order? Do these hooks cover all possible scenarios? I’m feeling there are instances?

    Also, in some orders, the USD value for the product is used, while the order currency meta is set as TRY!

    Thread Starter alkateb

    (@alkateb)

    I also have this issue, which is happening with orders I’m creating programatically:

    https://drive.google.com/file/d/1DZak4W7gMBJbUz4-nKGtREhnG1niCpsj/view?usp=sharing

    This product has a price of $0.1, and in TRY it should be around 0.74, as you can see! Rate is set to null, and the price charged was 0.1, which is not what the order currency is!

    I’m using this code to place this order automatically:

    
    $WOOCS->set_currency('TRY');
    $address = array(
      'first_name' => 'My name',
      'last_name'  => 'My last name',
      'email'      => '[email protected]',
    );
    $order = wc_create_order();
    $order->add_product(get_product($product_id));
    $order->set_address( $address, 'billing' );
    $payment_gateways = WC()->payment_gateways->payment_gateways();
    $order->set_payment_method($payment_gateways['wallet']);
    $order->calculate_totals();
    woo_wallet()->wallet->debit(826, $order->get_total(), 'For order #' . $order->id, $order->id);
    $order->set_customer_id(826);
    $order->update_status("wc-completed", $id, TRUE);
    
    Plugin Support mediawebster

    (@mediawebster)

    Hello

    This code should work correctly.

    I think you need to check the ability of your code to work in ajax mode. Because if you change some data on the checkout page, the order form is updated in ajax mode

    orders I’m creating programatically:
    To add data about current currency

                                update_post_meta($order_id, '_order_currency', $currency);
    
                                update_post_meta($order_id, '_woocs_order_rate', $currencies[$currency]['rate']);
    
                                update_post_meta($order_id, '_woocs_order_base_currency', $this->default_currency);
    
                                update_post_meta($order_id, '_woocs_order_currency_changed_mannualy', time());
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Currency is switching on its own’ is closed to new replies.