为什么要返回整个计费地址?
我试图最大程度地减少帐单地址,如果“客户已经购买了某些东西或从他的帐户中保存了他的地址”
它有效,但它不呼应地址_2它只是回应了整个计费地址 ,我做错了什么?
//hide billing address from checkout if the address is already entered before
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
if( is_user_logged_in() && has_billing()){
unset($fields['billing']);
$fields['billing'] = array();
}
return $fields;
}
// Check the meta of Postcode and Country if they are entered.
function has_billing($user_id = false){
if(!$user_id)
$user_id = get_current_user_id();
$shipping_postcode = get_user_meta( $user_id, 'billing_postcode', true );
$shipping_country = get_user_meta( $user_id, 'billing_country', true );
// Fetch more meta for the condition has needed.
if($shipping_postcode && $shipping_country){
return $address_fields['address_2'];
}
}
I'm trying to minimize the billing address if the billing address is already entered before "the customer already bought something or saved his address from his account"
It works but it doesn't echo address_2 it just echo the whole billing address
,What I'm doing wrong?
//hide billing address from checkout if the address is already entered before
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
if( is_user_logged_in() && has_billing()){
unset($fields['billing']);
$fields['billing'] = array();
}
return $fields;
}
// Check the meta of Postcode and Country if they are entered.
function has_billing($user_id = false){
if(!$user_id)
$user_id = get_current_user_id();
$shipping_postcode = get_user_meta( $user_id, 'billing_postcode', true );
$shipping_country = get_user_meta( $user_id, 'billing_country', true );
// Fetch more meta for the condition has needed.
if($shipping_postcode && $shipping_country){
return $address_fields['address_2'];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,从您的代码来看,尚不清楚如何定义
$ adville_fields
根据 https://woocommerce.io.github.io/code-reference/classes/classes/classes/classes/classes/ woocommerce.html
First of all, from your code, is not clear how is defined
$address_fields
According to https://woocommerce.github.io/code-reference/classes/WooCommerce.html