Jak wyłączyć pole na stronie kasy woocommerce [duplikat]
Jan 02 2021
Próbuję wyłączyć pola adresu 1 i 2 na stronie kasy. Użyłem poniższego działającego kodu na stronie mojego konta, próbowałem użyć kodu po edycji na stronie kasy, aby wyłączyć pole adresu 1 i adresu 2. Ale niestety to nie działa, uprzejmie pomóż.
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;
}
Odpowiedzi
2 suii Jan 02 2021 at 14:55
Dodaj is_checkout()
swój warunek, a następnie zmień pola na billing_address_1 i 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;
}