I have fetched the value of _order_total_base_currency (from Aelia Currency Switcher) which is already converting in AUD. Having this value I want it converted into USD and display on my custom meta-box.
The code I have right now is doing just that, but by having a fixed multiplier of 0.79 (since 1 AUD = 0.79 USD).
What I like to do however is replace the "0.79" to a variable value that is an updated exchange rate perhaps coming from Google API?
Here is my code:
add_action( 'add_meta_boxes', 'cdmb_add_meta_box');
function cdmb_add_meta_box( $post_id ) {
add_meta_box(
'woocommerce-order-my-custom',
__('USD Currency display','wc-usd-display'),
'cdmb_display_meta_box',
'shop_order',
'side',
'core'
);
}
// The metabox content
function cdmb_display_meta_box() {
// Get
global $post;
$total_usd = (get_post_meta( $post->ID, '_order_total_base_currency', true )) * 0.79;
$total_usd .= get_post_meta( $post->ID, '_order_total_base_currency', true );
?>
<table id="wc_cdmb_display_meta_box">
<tr>
<th><strong><?php esc_html_e( 'Order Total Base Currency', 'wc-usd-display' ) ?> : </strong></th>
<td><?php echo esc_html( ( empty( $total_usd ) ) ? __( 'N/A', 'wc-usd-display' ) : number_format(floatval($total_usd), 2) ); ?></td>
</tr>
</table>
<?php
}
The third party plugin Aelia Currency Switcher is outside of this. I already got what I want from it which is the value of _order_total_base_currency. Use the value as source to convert it to USD.
I'll appreciate all your help.