douju7503 2017-08-07 06:35 采纳率: 0%
浏览 30

显示获取的基本货币,然后转换为USD值并显示在自定义元框上

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
}

Custom meta box USD display

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么