Как отключить поле на странице оформления заказа 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;
}