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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分