• 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/HVvnBgc

    I 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 = '&nbsp;<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)
  • Hi @mrthiemann,

    Your WooCommerce customers can subscribe to the “WooCommerce Customers” list via a checkbox on the checkout page.

    Simply go to the MailPoet > Settings > WooCommerce tab and check the “Opt-in on checkout” option.

    Thread Starter mrthiemann

    (@mrthiemann)

    Hey MailPoet, thanks for your answer!

    That also works flawlessly!
    But I would like to have this checkbox already with the “normal” registration.

    Thread Starter mrthiemann

    (@mrthiemann)

    the checkbox for the newsletter is displayed correctly on the standard register page (/wp-signup.php).
    Image: https://ibb.co/b368hVs

    The checkbox is active in the MailPoet settings.
    Image: https://ibb.co/DVdQ47z

    But unfortunately I don’t get this implemented in the registry by WcfM

    I think your code for embedding is in mailpoet/lib/subscription/registration.php

    I tried to use parts of it … the checkbox is shown, but it doesn’t work.

    // 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() {
    
        print '<p class="registration-form-mailpoet">
          <label for="mailpoet_subscribe_on_register">
            <input
              type="checkbox"
              id="mailpoet_subscribe_on_register"
              value="1"
              name="mailpoet[subscribe_on_register]"
            />&nbsp;' . esc_attr($label) . '
          </label>
        </p>';

    Can you help me? Thanks, Karsten

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘checkbox on user registration’ is closed to new replies.