checkbox on user registration
-
Hey Commnunity,
is it possible to include a checkbox on the user registration page?
Unfortunately I can only find the form editor, but I cannot remove the “Email address” field there.as in the picture, I would like it
https://ibb.co/HVvnBgcI insert this checkbox with a snippet. However, this is not yet configured for MailPoet
// Remove "(optional)" label for this checkbox add_filter( 'woocommerce_form_field' , 'remove_optional_custom_field_label', 10, 4 ); function remove_optional_custom_field_label( $field, $key, $args, $value ) { if( 'receive_newsletter' === $key && is_wc_endpoint_url( 'edit-account' ) ) { $optional = ' <span class="optional">(' . esc_html__( 'optional', 'woocommerce' ) . ')</span>'; $field = str_replace( $optional, '', $field ); } return $field; } // Display a custom checkbox in My Account > Account details add_action( 'woocommerce_register_form', 'add_account_newsletter_checkbox_field' ); add_action( 'woocommerce_edit_account_form', 'add_account_newsletter_checkbox_field' ); function add_account_newsletter_checkbox_field() { woocommerce_form_field( 'receive_newsletter', array( 'type' => 'checkbox', 'class' => array('form-row-wide'), 'label' => __( 'M?chtest Du unseren Newsletter?', 'woocommerce' ), 'clear' => true, ), get_user_meta(get_current_user_id(), 'receive_newsletter', true ) ); } // Save registration checkbox field value add_action( 'woocommerce_created_customer', 'save_account_registration_field' ); function save_account_registration_field( $customer_id ) { $value = isset( $_POST['receive_newsletter'] ) ? '1' : '0'; update_user_meta( $customer_id, 'receive_newsletter', $value ); } // Save checkbox field value for My Account > Account details add_action( 'woocommerce_save_account_details', 'save_account_details_newsletter_checkbox_field', 10, 1 ); function save_account_details_newsletter_checkbox_field( $user_id ) { $value = isset( $_POST['receive_newsletter'] ) ? '1' : '0'; update_user_meta( $user_id, 'receive_newsletter', $value ); }
Thanks =)
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘checkbox on user registration’ is closed to new replies.