• Resolved Rob

    (@seomandarin)


    Hi,

    There’s one more thing I can’t seem to wrap my head around.
    The freight company needs to declare USD instead of CNY(chinese yuan) which is used on checkout.

    So what I want to do is for product field “Item Cost” and “Order Total Amount” to converse it to USD when exporting.

    For example the product cost 100CNY then Item Cost should do 100×0.147721 = “14.77” (USD)
    Order total amount should do price product 1 + product 2 x0.147721

    Is there a way to do this in a function?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi Rob

    What api will we use to get exchange rates? https://fixer.io/ ?
    thanks, alex

    Thread Starter Rob

    (@seomandarin)

    Hi Alex,

    Yes I assume fixer.io will work just fine!

    Thanks

    Plugin Author algol.plus

    (@algolplus)

    I use this url to get necessary rate https://api.fixer.io/latest?base=CNY&symbols=USD

    class WOE_currency_mod {
    	var $rate = false;
    	
    	function __construct() {
    		add_filter('woe_get_order_value_order_total',array($this,'convert_cny_usd'), 10, 2);
    		add_filter('woe_get_order_product_value_item_price',array($this,'convert_cny_usd'), 10, 2);
    	}	
    	
    	function convert_cny_usd($value, $order) {
    		return round( $value * $this->get_rate(), 2 );
    	}
    	
    	function get_rate() {
    		if( $this->rate === false) {
    			$response = wp_remote_get("https://api.fixer.io/latest?base=CNY&symbols=USD");
    			$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
    			$this->rate = $api_response['rates']['USD'];
    		}
    		return $this->rate;
    	}
    }	
    new WOE_currency_mod();
    Thread Starter Rob

    (@seomandarin)

    Works like a charm! I Wish I had your skills ??

    Many thanks

    Regards

    Plugin Author algol.plus

    (@algolplus)

    you’re welcome.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Auto currency conversion’ is closed to new replies.