doubaran2438 2017-08-03 08:38
浏览 36
已采纳

从Aelia Currency Switcher获取'_order_total_base_currency'值并显示在自定义字段元框中

I like to get the value from the Aelia Currency Switcher plugin which is the '_order_total_base_currency' and make a simple USD conversion then display it on my custom field metabox. How do I fetch that value so I can use it for calculation, and then display?

Here is my code:

// Adding the metabox (on the right side)
add_action( 'add_meta_boxes', 'cdmb_add_meta_box');
function cdmb_add_meta_box() {

    add_meta_box(
        'woocommerce-order-my-custom',
        __('USD Currency display'),
        'cdmb_display_meta_box',
        'shop_order',
        'side',
        'core'
    );
}
// The metabox content
function cdmb_display_meta_box() {
    // Get

    $total_usd = (get_post_meta( $post->ID, '_order_total_base_currency', true )) / 0.75;
    $total_usd .= get_post_meta( $post->ID, '_order_total_base_currency', true );

    echo '<p>' . $total_usd . '</p>';

}

// Save/Update the meta data
add_action( 'save_post', 'cdmb_save_meta_box_data' );
function cdmb_save_meta_box_data( $post_id ) {

// Only for shop order
if ( 'shop_order' != $_POST[ 'post_type' ] )
    return $post_id;

// Checking that is not an autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    return $post_id;

## SETTING AND UPDATING DATA ##

update_post_meta( $post_id, 'total-usd', sanitize_text_field( $_POST[ 'total-usd' ] ) );
}

?>

enter image description here

  • 写回答

1条回答 默认 最新

  • dqk94069 2017-08-07 00:08
    关注

    After spending time with it, I found the answer. I am now able to fetch the value for '_order_total_base_currency' from the Aelia Currency Switcher plugin.

    It needs the global $post; before the variable $total_usd.

    The code should be this:

    function cdmb_display_meta_box() {
        // Get
    
    global $post;
        $total_usd = get_post_meta( $post->ID, '_order_total_base_currency', true );
    
        echo '<p>' . $total_usd . '</p>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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的速度时间图像)我想问线路信息是什么