php - 在订单详细信息中显示自定义 WooCommerce 结帐字段并使其可编辑
问题描述
我正在更新 WooCommerce 的插件,并且我有一个hooks.php
处理 WooCommerce 钩子的文件。我在结帐时添加了四个新的计费字段,我需要在订单详细信息中显示它们;我还需要使它们可编辑。
这是我成功显示我的字段的代码:
add_action('woocommerce_admin_order_data_after_billing_address', function($order)
echo p(strong(__('Codice Fiscale', 'fatt-24')).': <br />' . order_c_fis($order));
echo p(strong(__('Partita Iva / VAT number', 'fatt-24')).': <br />' . order_p_iva($order));
echo p(strong(__('Codice destinatario', 'fatt-24')) . ': <br />' . order_recipientcode($order));
echo p(strong(__('Indirizzo PEC', 'fatt-24')) . ': <br />' . order_pec_address($order));
}, 10, 1);
我无法编辑和保存它。
解决方案
用于在管理订单详细信息中显示为可编辑字段
add_filter('woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1);
function custom_admin_billing_fields($fields) {
$fields['billing_fiscalcode'] = array(
'label' => __('billing_fiscalcode', 'woocommerce'),
'show' => true,
);
$fields['billing_vatcode'] = array(
'label' => __('billing_vatcode', 'woocommerce'),
'show' => true,
);
$fields['billing_recipientcode'] = array(
'label' => __('billing_recipientcode', 'woocommerce'),
'show' => true,
);
$fields['billing_pecaddress'] = array(
'label' => __('billing_pecaddress', 'woocommerce'),
'show' => true,
);
return $fields;
}
add_action('woocommerce_admin_order_data_after_billing_address', 'display_billing_options_value_in_admin_order', 10, 1);
function display_billing_options_value_in_admin_order($order) {
if ($value = get_post_meta($order->get_id(), 'billing_fiscalcode', true))
echo '<p><strong>' . __('Billing Fiscalcode', 'woocommerce') . ':</strong> ' . $value . '</p>';
if ($value = get_post_meta($order->get_id(), 'billing_vatcode', true))
echo '<p><strong>' . __('billing_vatcode', 'woocommerce') . ':</strong> ' . $value . '</p>';
if ($value = get_post_meta($order->get_id(), 'billing_recipientcode', true))
echo '<p><strong>' . __('billing_recipientcode', 'woocommerce') . ':</strong> ' . $value . '</p>';
if ($value = get_post_meta($order->get_id(), 'billing_pecaddress', true))
echo '<p><strong>' . __('billing_pecaddress', 'woocommerce') . ':</strong> ' . $value . '</p>';
}
推荐阅读
- python - 如何通过将 dict 键替换为其值来形成字符串
- python - Python 列表想要列表的总和,不包括从列表中的数字到另一个数字的值范围,在本例中为 6 到 9
- android - 为什么Android ViewPager2 类是final?
- excel - 如何根据当前工作表路径进行合并
- sql - 如何覆盖此函数以将数据存储在数据库中?
- if-statement - 如何从具有不同字数的异构变量中提取中间名?
- reactjs - Highcharts-React 返回 Object 并且 React 给出错误 - React.createElement: type is invalid
- python - 使用串行连接进行控制时,如何使用 arduino 控制 bldc 电机?
- java - 由于“插件 uBlock0@raymondhill.net 未正确签名”,Selenium 未安装 Firefox 插件
- html - 离子选择无法使用动态值正确渲染?离子 4