订单页不直接展示国家 点右上角的地址编辑会正常显示国家
add_filter( 'woocommerce_order_formatted_billing_address', 'custom_display_country_in_address', 10, 2 );
add_filter( 'woocommerce_order_formatted_shipping_address', 'custom_display_country_in_address', 10, 2 );
function custom_display_country_in_address( $address, $order ) {
// 确保国家字段始终存在
$address['country'] = $order->get_billing_country(); // 或 get_shipping_country()
return $address;
}
// 强制在订单详情页输出国家(即使模板未调用)
add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_country_fallback', 10, 1 );
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'display_country_fallback', 10, 1 );
function display_country_fallback( $order ) {
$country = $order->get_billing_country();
if ( ! empty( $country ) ) {
echo '<p><strong>' . __( 'Country', 'woocommerce' ) . ':</strong> ' . esc_html( $country ) . '</p>';
}
}
woocommerce 后台订单地址那边不直接展示国家
前端订单页国家显示问题及解决代码
于 2025-06-28 17:38:10 首次发布
19

被折叠的 条评论
为什么被折叠?



