在woocommerce中按订单显示自定义字段 [英] Show custom field on order in woocommerce

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

问题描述

我在一家网上商店工作并遵循本教程 http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/ 将一些客户字段添加到我的帐单中.

Im working on a webshop and follwoing this tutorial http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/ to add some customes fields to my billing.

// 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;
}

这增加了我的领域.到现在为止还挺好.所以我的问题是:

This adds my field. So far so good. So my problem is:

如何在订单视图中查看这个新字段?帐单详情仅显示通常的帐单字段.

How can I view this new field in the orders view? Details for billing only show the usual billing fields.

推荐答案

第一个答案 (Cesar) 几乎是正确的.如果有人遇到过这篇试图找出相同内容的旧帖子,下面是在原始海报给出的代码之后插入到您的 functions.php 文件中所需的代码,根据他/她提供的变量量身定制.请注意,它们使用字段名称billing_gls_name",并且在我们的新函数中将其引用为_billing_gls_name".开头的额外_"是必要的.这适用于运行 WooCommerce 2.0.3 的 Wordpress 3.5.1.

The first answer (Cesar) was CLOSE to being correct. In case anyone ever comes across this old post trying to find out the same thing, below is the code needed to insert into your functions.php file after the code given by the original poster, tailored to his/her variables as provided. Note that they use the field name "billing_gls_name" and that this is referenced in our new function as "_billing_gls_name". The extra "_" at the beginning is necessary. This works on Wordpress 3.5.1 running WooCommerce 2.0.3.

function your_custom_field_function_name($order){
    echo "<p><strong>Name of pickup person:</strong> " . $order->order_custom_fields['_billing_gls_name'][0] . "</p>";
}

add_action( 'woocommerce_admin_order_data_after_billing_address', 'your_custom_field_function_name', 10, 1 );

这篇关于在woocommerce中按订单显示自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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