我在网上商店工作,然后按照本教程http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/将一些客户字段添加到我的账单中 .
// 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_gls_name'] = array(
'label' => __('Name for pickup person', 'woocommerce'),
'placeholder' => _x('Name', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
这增加了我的领域 . 到现在为止还挺好 . 所以我的问题是:
如何在订单视图中查看此新字段?计费详细信息仅显示常用的结算字段 .
3 回答
第一个答案(塞萨尔)关闭是正确的 . 如果有人遇到这个老帖子试图找出相同的东西,下面是在原始海报给出的代码之后插入到functions.php文件中所需的代码,根据他/她提供的变量量身定制 . 请注意,它们使用字段名称“billing_gls_name”,并在我们的新函数中将其引用为“billing_gls_name” . 开头的额外“”是必要的 . 这适用于运行WooCommerce 2.0.3的Wordpress 3.5.1 .
在定义自定义字段(您在上面提到的代码中所做的)后,将下面提到的代码添加到:
处理你的领域
将其作为订单元数据保存在数据库中
在Woocommerce-> Orders部分的“订单详细信息”中显示
Process your field:
Save Field in the DB as Order Meta Data:
And finally display it in the Order details screen:
添加操作
woocommerce_admin_order_data_after_billing_address
您可以在结算信息后插入一些数据 . 自定义字段位于$order->order_custom_fields
数组下 .