Cách tắt trường trong trang thanh toán woocommerce [trùng lặp]

Jan 02 2021

Tôi đang cố vô hiệu hóa các trường địa chỉ 1 và địa chỉ 2 của mình trên trang thanh toán. Tôi đã sử dụng mã làm việc dưới đây trên trang tài khoản của mình, tôi đã cố gắng sử dụng mã sau khi chỉnh sửa trên trang thanh toán để vô hiệu hóa trường địa chỉ 1 và địa chỉ 2. Nhưng tiếc là nó không hoạt động, Vui lòng giúp đỡ.

add_filter( 'woocommerce_checkout_fields', 'readonly_billing_account_fields', 25, 1 );
function readonly_billing_account_fields ( $billing_fields ) { // Only my account billing address for logged in users if( is_user_logged_in() && is_account_page() ){ $readonly = ['readonly' => 'readonly'];

        $billing_fields['address_1']['custom_attributes'] = $readonly;
        $billing_fields['address_2']['custom_attributes'] = $readonly;
    }
    return $billing_fields;
}

Trả lời

2 suii Jan 02 2021 at 14:55

Thêm is_checkout()điều kiện của bạn, sau đó thay đổi các trường thành billing_address_1 và 2.

add_filter( 'woocommerce_checkout_fields', 'readonly_billing_account_fields', 25, 1 );
function readonly_billing_account_fields ( $billing_fields ) { // Only my account billing address for logged in users if( (is_user_logged_in() && is_account_page()) || is_checkout()){ $readonly = ['readonly' => 'readonly'];

        $billing_fields['billing']['billing_address_1']['custom_attributes'] = $readonly;
        $billing_fields['billing']['billing_address_2']['custom_attributes'] = $readonly;
    }
    return $billing_fields;
}