要更改管理订单编辑页面中的格式化帐单地址,请尝试以下操作(请注意,您可能需要进行一些调整才能获得所需的显示):
add_filter( 'woocommerce_order_get_formatted_billing_address', 'filter_admin_order_formatted_billing_address', 10, 3 );
function filter_admin_order_formatted_billing_address( $address, $raw_address, $order ) {
global $pagenow, $typenow;
$address .= '<br>' . $pagenow . '<br>' . $typenow;
if ( ( $pagenow === 'post.php' && $typenow === 'shop_order' )
|| ( $pagenow === 'admin.php' && isset($_GET['page']) && isset($_GET['action'])
&& $_GET['page'] === 'wc-orders' && $_GET['action'] === 'edit' ) ) :
$address = $raw_address['first_name'] . ' ' . $raw_address['last_name'] . '<br>';
if ( isset($raw_address['company']) && $raw_address['company'] ) {
$address .= $raw_address['company'] . '<br>';
}
if ( isset($raw_address['address_1']) && $raw_address['address_1'] ) {
$address .= __('Address') . ': '. $raw_address['address_1'] . '<br>';
}
if ( isset($raw_address['address_2']) && $raw_address['address_2'] ) {
$address .= __('Villa/Bldg/Number') . ': '. $raw_address['address_2'] . '<br>';
}
if ( isset($raw_address['postcode']) && $raw_address['postcode'] ) {
$address .= __('Zone Number') . ': '. $raw_address['postcode'] . '<br>';
}
if ( isset($raw_address['city']) && $raw_address['city'] ) {
$address .= $raw_address['city'] . '<br>';
}
$states = WC()->countries->get_states( esc_attr($raw_address['country']) );
if ( isset($raw_address['state']) && isset($states[$raw_address['state']]) ) {
$address .= $states[$raw_address['state']] . '<br>';
}
$countries = WC()->countries->get_countries();
if ( isset($raw_address['country']) && isset($countries[$raw_address['country']]) ) {
$address .= $countries[$raw_address['country']] . '<br>';
}
endif;
return $address;
}
代码位于子主题的functions.php 文件中(或插件中)。已测试并有效。
对于运输格式地址(如果需要),请使用:
add_filter( 'woocommerce_order_get_formatted_shipping_address', 'filter_admin_order_formatted_shipping_address', 10, 3 );
function filter_admin_order_formatted_shipping_address( $address, $raw_address, $order ) {
global $pagenow, $typenow;
$address .= '<br>' . $pagenow . '<br>' . $typenow;
if ( ( $pagenow === 'post.php' && $typenow === 'shop_order' )
|| ( $pagenow === 'admin.php' && isset($_GET['page']) && isset($_GET['action'])
&& $_GET['page'] === 'wc-orders' && $_GET['action'] === 'edit' ) ) :
$address = $raw_address['first_name'] . ' ' . $raw_address['last_name'] . '<br>';
if ( isset($raw_address['address_1']) && $raw_address['address_1'] ) {
$address .= __('Address') . ': '. $raw_address['address_1'] . '<br>';
}
if ( isset($raw_address['address_2']) && $raw_address['address_2'] ) {
$address .= __('Villa/Bldg/Number') . ': '. $raw_address['address_2'] . '<br>';
}
if ( isset($raw_address['postcode']) && $raw_address['postcode'] ) {
$address .= __('Zone Number') . ': '. $raw_address['postcode'] . '<br>';
}
if ( isset($raw_address['city']) && $raw_address['city'] ) {
$address .= $raw_address['city'] . '<br>';
}
$states = WC()->countries->get_states( esc_attr($raw_address['country']) );
if ( isset($raw_address['state']) && isset($states[$raw_address['state']]) ) {
$address .= $states[$raw_address['state']] . '<br>';
}
$countries = WC()->countries->get_countries();
if ( isset($raw_address['country']) && isset($countries[$raw_address['country']]) ) {
$address .= $countries[$raw_address['country']] . '<br>';
}
endif;
return $address;
}