在Woocommerce管理订单编辑页面中显示自定义结帐字段值 [英] Display custom checkout field value in Woocommerce admin order edit pages

查看:106
本文介绍了在Woocommerce管理订单编辑页面中显示自定义结帐字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在functions.php中具有函数:

I have the function in functions.php:

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['billing']['billing_infos'] = array(
        'type'      => 'textarea',
        'label'     => __('Podaj NIP', 'woocommerce'),
    'placeholder'   => _x('Tutaj możesz wpisać NIP', 'placeholder', 'woocommerce'),
    'required'  => false,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

     return $fields;
}   

此代码将自定义字段添加到帐单表单中。运作正常,是因为当我像普通用户一样下订单时会看到它。问题出在管理面板中来自此字段的数据。我看不到请问对此有任何帮助吗?

This code is adding custom field to billing form. It's working fine because I see it when I make an order like normal user. The problem is with data from this field in admin panel. I can't see it. Any help on this please?

推荐答案

此缺少的挂钩函数将在订单编辑页面的帐单详细信息下方显示您的自定义字段:

This missing hooked function will display your custom fields in Order edit page, below Billing details:

add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_billing_infos_to_admin_order_meta', 20, 1 );
function display_billing_infos_to_admin_order_meta( $order ){
    echo '<p><strong>'.__('Podaj NIP').':</strong> ' . get_post_meta( $order->get_id(), '_billing_infos', true ) . '</p>';
}

代码进入活动子主题(或活动主题)的function.php文件)。经过测试,可以正常工作。

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于在Woocommerce管理订单编辑页面中显示自定义结帐字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆