2
enter image description here我想我顯示的佔位符放在一個自定義字段在對後,或單個訂單頁面管理區的任何值。在Woocommerce編輯訂單頁面獲取自定義字段值定製metabox
我已經放在get_post_meta(get_the_id(), 'total-usd', true)
引號value=""
所以它不應該是空的裏面,但是當我點擊更新其仍顯示爲空。
我的代碼似乎有什麼錯?我感謝你的幫助。
這裏是我的代碼:
<?php
function cpmb_add_meta_box() {
add_meta_box(
'woocommerce-order-my-custom',
'USD Currency display',
'cpmb_display_meta_box',
'shop_order',
'normal',
'core'
);
}
add_action('add_meta_boxes', 'cpmb_add_meta_box');
function cpmb_display_meta_box($post) {
wp_nonce_field(plugin_basename(__POST__), 'cpmb-nonce-field');
$html = '<label id="total-usd" for="total-usd">';
$html .= '<strong>Total USD Currency</strong>';
$html .= '</label><br />';
$html .= '<input type="text" id="total-usd" name="Total USD Currency" value="' . get_post_meta(get_the_id(), 'total-usd', true) . '" placeholder="Enter Total here" />';
echo $html;
}
function cpmb_save_meta_box_data($post_id) {
if (cpmb_user_can_save($post_id, 'cpmb-nonce-field')){
if (isset($_POST['total-usd']) && 0 < count(strlen(trim($_POST['total-usd'])))) {
$total_usd = stripslashes(strip_tags($_POST['total-usd']));
update_post_meta($post_id, 'total-usd', $total_usd);
}
}
}
add_action('save_post', 'cpmb_save_meta_box_data');
function cpmb_user_can_save($post_id, $nonce) {
$is_autosave = wp_is_post_autosave($post_id);
$is_revision = wp_is_post_revision($post_id);
$is_valid_nonce = (isset($_POST[ $nonce ]) && wp_verify_nonce($_POST[ $nonce ], plugin_basename(__POST__)));
return ! ($is_autosave || $is_revision) && $is_valid_nonce;
}
?>
我明白了很多,感謝你在百忙一個後續問題。我如何迴應所顯示的顯示已被除以0.75等數字?喜歡而不是100它會顯示133.33? –
@FloranteFerrer請問,[這個答案是回答你的問題嗎?](https://stackoverflow.com/help/someone-answers)...我認爲它是回答...你在說什麼計算,因爲它不在你的問題?所以可能你應該澄清你的問題關於「計算」... – LoicTheAztec