我喜欢从Aelia Currency Switcher插件获取价值,这是' _order_total_base_currency'并进行简单的USD转换,然后将其显示在我的自定义字段元数据盒上。如何获取该值以便我可以将其用于计算,然后显示?
这是我的代码:
// 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' ] ) );
}
?>
答案 0 :(得分:0)
花了一些时间后,我找到了答案。我现在能够获取&#39; _order_total_base_currency&#39;的值。来自Aelia Currency Switcher插件。
它需要全球$ post;变量$ total_usd之前。
代码应为:
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>';