如果在WooCommerce结账时完成,则尽量减少账单地址



我正在尝试最小化计费地址如果用户已经填写了账单表单(从以前的订单中),或者如果用户之前已经从"我的账户"中填写了账单,则从结账时开始。页)。

我已经尝试了这个方法来完全隐藏账单地址,但它根本不起作用

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 true;
}
return false;
}

我做错了什么?

您正在取消正在提交的表单字段。如果您将它们隐藏在CSS中,则应该工作,或者您需要在单击checkout按钮时动态填充表单。

最新更新