woocommerce 결제 페이지에서 필드를 비활성화하는 방법 [중복]

Jan 02 2021

결제 페이지에서 내 주소 1 및 주소 2 필드를 비활성화하려고합니다. 내 계정 페이지에서 아래 작업 코드를 사용했으며 결제 페이지에서 주소 1 및 주소 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() ){ $readonly = ['readonly' => 'readonly'];

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

답변

2 suii Jan 02 2021 at 14:55

is_checkout()조건을 추가 한 다음 필드를 billing_address_1 및 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;
}