• Resolved vicentbeneito

    (@vicentbeneito)


    hi

    I have done an integration from WooCommerce to MailRelay. In WooCommerce I choose order-create. I select the fields (email and billing first name) and the customer data chosen in these fields is recorded on the MailRelay platform.

    Now, on the WooCommerce “account” page, a form appears to register as a customer, with only the email and password fields. From functions.php I create a new field for the customer name:

    with the woocommerce_register_form_start hook I create a new field:

    <label for="reg_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="first_name" id="reg_first_name" value="<?php if ( ! empty( $_POST['first_name'] ) ) esc_attr_e( $_POST[' first_name'] ) ?>" />

    I register and validate the field with the woocommerce_register_post hook and save it using the woocommerce_created_customer hook.

    It should be said that all of this, at the level of WordPress and WooCommerce, the code works correctly. The first_name is saved in both WordPress and WooCommerce.

    In Bit Integrations, I want to do an integration from customer-create to MailRelay. In the fields section, I match email (form fields) with email (mailrelay fields), and first name (form fields) with name (mailrelay fields).

    On the MailRelay platform, only the email field appears registered. The name field is not recorded. Remains empty.
    How can I correct this?

    Many thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support wayes001

    (@wayes001)

    Hello

    Could you please let us know where you created the “First Name” field? You mentioned that you created it from functions.php, but we couldn’t locate it. Could you please provide the URL path so we can check it?

    Additionally, we would like to inform you that Bit Integration currently supports default user registration fields.

    Thread Starter vicentbeneito

    (@vicentbeneito)

    The “First Name” field is created in functions.php, in child theme, in localhost for test. The WooCommerce form to create a new customer does not have a “First Name” field by default.

    // create field
    function wooc_extra_register_fields() {?>
    <p class="form-row form-row-wide">
    <label for="reg_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="first_name" id="reg_first_name" value="<?php if ( ! empty( $_POST['first_name'] ) ) esc_attr_e( $_POST['first_name'] ); ?>" />
    </p>
    <div class="clear"></div>
    <?php
    }
    add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );

    // validate and save field in WooCommerce/Wordpress

    function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
    if ( isset( $_POST['first_name'] ) && empty( $_POST['first_name'] ) ) {
    $validation_errors->add( 'first_name_error', __( 'Por favor, introduce tu nombre.', 'woocommerce' ) );
    }
    return $validation_errors;
    }
    add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );

    function wooc_save_extra_register_fields( $customer_id ) {
    if ( isset( $_POST['first_name'] ) ) {
    update_user_meta( $customer_id, 'billing_first_name', wc_clean( $_POST['first_name'] ) );
    //update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['first_name'] ) );
    // Guardar en WordPress (nombre estándar)
    $user_data = array(
    'ID' => $customer_id,
    'first_name' => sanitize_text_field( $_POST['first_name'] ),
    );
    wp_update_user( $user_data );
    }
    }
    add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

    With code above, a new field is created in WooCommerce account page, register new customer section. The value entered in the field is saved as the First Name, both in the WooCommerce customer data and in the First Name of the WordPress user data.

    In the Bit Integrations Field Map drop-down, the First Name field can be selected. I have tested Email (works) and Nickname (works). But if I select First Name, nothing appears in subscriber name in MailRelay platform.

    Plugin Support wayes001

    (@wayes001)

    We have checked the issue and noticed that the user’s first name is being updated, which is why the first name field is not sending the data.

    The code you are using to create the first name updates the customer details after the account is created. When an account is created from the “My Account” page, the customer is initially created without a first name. Your code then updates the customer with the first name, which is causing the issue.

    To resolve this, you need to update your code to include the first name when creating the customer. Alternatively, you can use the “Customer-Edit” trigger in WooCommerce, which should work as expected.

    Please note that whenever a user is created, the data will be sent to MailRelay.

    Thank you for your understanding.

    Thread Starter vicentbeneito

    (@vicentbeneito)

    Thanks for your help.

    I don’t understand some things…

    To resolve this, you need to update your code to include the first name when creating the customer.

    Doesn’t this code already include the first name when creating the customer?

    <p class="form-row form-row-wide">
    <label for="reg_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
    <input type="text" class="input-text" name="first_name" id="reg_first_name" value="<?php if ( ! empty( $_POST['first_name'] ) ) esc_attr_e( $_POST['first_name'] ); ?>" />
    </p>

    How could I update my code to include the first name when creating the customer?

    Please note that whenever a user is created, the data will be sent to MailRelay

    If a user is created with a form where the first name field alredy exists (my code provides a “first name” field on the customer creation form), shouldn’t the value of that field be sent to MailRelay, regardless of whether it is updated or not?

    Thank you for your attention.

    Plugin Support wayes001

    (@wayes001)

    The code you are using for “First Name” inserts the value into the WordPress user to update the first name field. It doesn’t insert the value when the user is created; it inserts the value after the user has been created.

    You can use the “Customer-Edit” trigger in WooCommerce to send data to MailRelay, as it sends data after updating the first name. However, please note that when you edit any customer in the WordPress backend, it will also send data for the customer, as the trigger is “Customer-Edit.”

    Please note that whenever a user is created, the data will be sent to MailRelay

    Thread Starter vicentbeneito

    (@vicentbeneito)

    I think is a good idea use the trigger “customer-edit”. I will test it.
    Many thanks.

    Anyway, how could the First Name in the Bit Integrations Field Map drop-down be used in WooCommerce default registration form?

    Plugin Support wayes001

    (@wayes001)


    It is the same field mapping process. Simply select “First Name” from the drop-down and map it with the Mailrealy “Name” field as you would with any other field mapping

    Here is the screenshot: https://i.imgur.com/1jDET65.png

    • This reply was modified 4 months, 3 weeks ago by wayes001.
    Thread Starter vicentbeneito

    (@vicentbeneito)

    yes, it is the same field mapping process, but the default woocommerce form only has email and password fields…

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.