So deaktivieren Sie das Feld auf der Woocommerce-Checkout-Seite [Duplikat]
Jan 02 2021
Ich versuche, meine Felder für Adresse 1 und Adresse 2 auf der Checkout-Seite zu deaktivieren. Ich habe den folgenden Arbeitscode auf meiner Kontoseite verwendet. Ich habe versucht, den Code nach dem Bearbeiten auf der Checkout-Seite zu verwenden, um die Felder Adresse 1 und Adresse 2 zu deaktivieren. Aber leider funktioniert es nicht, bitte helfen.
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;
}
Antworten
2 suii Jan 02 2021 at 14:55
Fügen Sie is_checkout()
Ihre Bedingung hinzu und ändern Sie die Felder in billing_address_1 und 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;
}