Woocommerce Hook and Cart's Currency

Hi,

I was wondering would anyone know how or encountered before where I can add function hook to do some coding before passing to payment gateway for Woocommerce. Secondly, change the entire shopping cart's currency, the website is currently using Woocommerce and WPML?

  • Predrag Dubajic
    • Support

    Hey @Timothy,

    Hope you're doing well today :slight_smile:

    I believe that this is the hook you are looking for:
    woocommerce_before_checkout_process
    For example:
    add_action( 'woocommerce_before_checkout_process', 'initiate_order' , 10, 1 );

    Secondly, change the entire shopping cart's currency, the website is currently using Woocommerce and WPML?

    Currency can be changed by going to Woocommerce > Settings > General tab where you will see Currency Options section and currency picker.

    Hope this helps :slight_smile:

    Best regards,
    Predrag

  • Timothy
    • Site Builder, Child of Zeus

    Hi Predrag,

    Thank you so so much for your help. I got the first step working but still trying to get the second part working.

    add_action('woocommerce_before_checkout_process','change_currency_on_checkout');
    
    function change_currency_on_checkout()
    {
    	global $woocommerce,$sitepress;
    	unset($data);
    	$data[0]['country'] = "JP";
    	$data[0]['currency'] = "JPY";
    
    	foreach($data as $item)
    	{
    		if($woocommerce->customer->shipping_country == $item['country'])
    		{
    			// Change the Currency Here
    		}
    	}
    	exit;
    }

    What I want to do is once it finds the country of the customer's shipping country it will change if within the array. For example if user's shipping address is Japan it will then change the currency to JPY using WPML's currency switcher.

    I tried both coding but doesn't seem to work.
    (1)
    do_action('wcml_switch_currency', 'JPY');

    (2)

    function wcml_custom_currency($current)
    	{
    		return 'JPY';
    	}
    	add_filter('wcml_client_currency', 'wcml_custom_currency');

    Have any ideas how I can nail these two together?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.