首页 文章

如果已经完成WooCommerce,请隐藏地址

提问于
浏览
0

我正在寻找一种方法来隐藏我的woocommerce主题的结帐页面上的帐单邮寄地址,如果用户已经填写了帐单表单(来自之前的订单或者用户之前已经从“我的帐户”页面完成了) .

如果用户已登录(见下文),我已经找到了在结帐页面上完全隐藏结算/发货表单的方法,但是我无法找到办法完成上述操作 .

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    if( is_user_logged_in() ){
        unset($fields['billing']);
        $fields['billing'] = array();
    }
    return $fields;
}

任何的想法?

谢谢!

1 回答

  • 3

    它将取决于你认为是一个完全完成的地址我制作的片段功能你可以用来进一步 .

    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;
    }
    

    注意:前缀 shipping_ 有一个用于计费( billing_ ) .

    编辑:这里元键 billing_address_1billing_address_2 总是前缀可以是 billing_shipping_

    此外,如果由于某种原因您没有在用户元键中关联的送货地址或帐单邮寄地址,但客户曾执行订单,您可以检查此代码以获取订单地址 .

    Woocommerce WC_Order get_shipping_address()没有作为数组返回(旧帖子可能不再有效)

相关问题