Php woocommerce正在发货表下添加自定义字段(我的帐户订单视图/谢谢)
在这两篇文章()的帮助下,我在结帐、我的帐户、单一订单、管理员和电子邮件中添加了自定义字段。但是还有3个区域我想显示这个自定义字段,我找不到显示它们所需的钩子。我在网上搜索,但一点运气都没有。如果有人能在这方面指导我,我会很高兴的 1-在“谢谢”页面的“配送地址”表下 2-在“我的帐户”页面的“订单”视图中的“发货地址表”下 3-我想在我的帐户上显示地址中的字段。但它只有在单击“编辑”时才可见 这是我用来添加额外字段的代码,目前为止它仍在工作Php woocommerce正在发货表下添加自定义字段(我的帐户订单视图/谢谢),php,wordpress,woocommerce,Php,Wordpress,Woocommerce,在这两篇文章()的帮助下,我在结帐、我的帐户、单一订单、管理员和电子邮件中添加了自定义字段。但是还有3个区域我想显示这个自定义字段,我找不到显示它们所需的钩子。我在网上搜索,但一点运气都没有。如果有人能在这方面指导我,我会很高兴的 1-在“谢谢”页面的“配送地址”表下 2-在“我的帐户”页面的“订单”视图中的“发货地址表”下 3-我想在我的帐户上显示地址中的字段。但它只有在单击“编辑”时才可见 这是我用来添加额外字段的代码,目前为止它仍在工作 // HOUSE NUMBER EXTRA F
// HOUSE NUMBER EXTRA FIELD
// display shipping House Number in checkout and my account edit shipping address
add_filter( 'woocommerce_shipping_fields', 'add_shipping_house_number_field' );
function add_shipping_house_number_field( $fields ) {
$fields['shipping_house_number'] = array(
'label' => __( 'House Number', 'woocommerce' ),
//'required' => true,
'class' => array( 'form-row-first' ),
'priority' => 61,
);
return $fields;
}
// Display editable custom fields on admin single order pages (backend new order) edit pages inside edit shipping section
add_filter( 'woocommerce_admin_shipping_fields' , 'add_order_admin_edit_shipping_house_number' );
function add_order_admin_edit_shipping_house_number( $fields ) {
// Include shipping house_number as editable field
$fields['house_number'] = array( 'label' => __( 'House Number', 'woocommerce' ), 'show' => '0' );
return $fields;
}
// Load Ajax custom field data as customer billing/shipping address fields in backend new order (data will be pulled from the database)
add_filter( 'woocommerce_ajax_get_customer_details' , 'add_custom_fields_to_ajax_customer_details', 10, 3 );
function add_custom_fields_to_ajax_customer_details( $data, $customer, $user_id ) {
$data['shipping'][house_number] = $customer->get_meta('shipping_house_number');
return $data;
}
// Display reordered editable custom fields on admin single User pages
add_filter( 'woocommerce_customer_meta_fields', 'house_number_customer_meta_fields', 10, 1 );
function house_number_customer_meta_fields( $fields ) {
$fields['shipping']['fields']['shipping_house_number'] = array(
'label' => __( 'House Number', 'woocommerce' ),
);
return $fields;
}
// Adding custom placeholder to woocommerce formatted address only on Backend
add_filter( 'woocommerce_localisation_address_formats', 'admin_localisation_address_formats', 50, 1 );
function admin_localisation_address_formats( $address_formats ){
// Only in backend (Admin)
if( is_admin() || ! is_wc_endpoint_url() ) {
foreach( $address_formats as $country_code => $address_format ) {
$address_formats[$country_code] .= "\n{house_number}";
}
}
return $address_formats;
}
// Custom placeholder replacement to woocommerce formatted address
add_filter( 'woocommerce_formatted_address_replacements', 'custom_formatted_address_replacements', 10, 2 );
function custom_formatted_address_replacements( $replacements, $args ) {
$replacements['{house_number}'] = ! empty($args['house_number']) ? $args['house_number'] : '';
return $replacements;
}
// Add the shipping house number value to be displayed on email notifications under shipping address
add_filter( 'woocommerce_order_formatted_shipping_address', 'add_shipping_house_number_to_formatted_shipping_address', 100, 2 );
function add_shipping_house_number_to_formatted_shipping_address( $shipping_address, $order ) {
global $pagenow, $post_type;
// Not on admin order edit pages (as it's already displayed).
if( ! ( $pagenow === 'post.php' && $post_type === 'shop_order' && isset($_GET['action']) && $_GET['action'] === 'edit' ) ) {
// Include shipping phone on formatted shipping address
$shipping_address['house_number'] = $order->get_meta('_shipping_house_number');
}
return $shipping_address;
}
对于感谢页面和我的帐户查看订单,您可以使用WC
woocommerce\u order\u get\u formatted\u shipping\u address
filter hook
function add_woocommerce_order_get_formatted_shipping_address( $address, $empty_content, $raw_address, $order ){
$address .= '<br/> this is custom text';
return $address;
}
add_filter( 'woocommerce_order_get_formatted_shipping_address', 'add_woocommerce_order_get_formatted_shipping_address', 10, 4 );
函数add\u woodcommerce\u order\u get\u formatted\u shipping\u address($address,$empty\u content,$raw\u address,$order){
$address.='
这是自定义文本';
返回$address;
}
添加过滤器('woocommerce\u order\u get\u formatted\u shipping\u address','add\u woocommerce\u order\u get\u formatted\u shipping\u address',10,4);
谢谢页面
我的帐户查看订单。
我的帐户编辑地址
你需要重写woocommerce\templates\myaccount\myaddress.php
你的主题或插件
您的代码不起作用,但我正在查看更多有关woocommerce\u order\u get\u formatted\u shipping\u address的信息。谢谢,顺便说一句