Customize Woocommerce Registration!

Asked

Viewed 669 times

-1

I have a project where I need to customize the Woocommerce registration form, it already has email and password. But I need to add the CNPJ field and validate if it is true and this information should also appear on the account details page.

Does anyone know if this is possible?

  • You want to develop at hand, programmatically or use some plugin?

1 answer

1

You can use this code in the funcions of your Theme or plugin, you can add the fields you need:

     add_action( 'woocommerce_edit_account_form', 'add_marketplace_fields_to_edit_account_form',1,1);
            function add_marketplace_fields_to_edit_account_form() {
                $user = wp_get_current_user();
                ?>


                <div class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">
                    <label for="account_first_name"><?php esc_html_e( 'CPF', 'woocommerce' ); ?></label>
                    <input type="text" v-mask="'###.###.###-##'" class="woocommerce-Input woocommerce-Input--text input-text" name="billing_cpf_cli" v-model="cpf_cli" autocomplete="given-name" />
                </div>
<?php }?>

to record you can use this hook:

function record_custommer_edit( $customer_id ) {



    if (isset($_POST['billing_cpf_cli']) && $_POST['billing_cpf_cli'] != '') {
        update_user_meta($customer_id, 'billing_cpf_cli', sanitize_text_field($_POST['billing_cpf_cli']));
    }

    if (isset($_POST['billing_rg_cli']) && $_POST['billing_rg_cli'] != '') {
        update_user_meta($customer_id, 'billing_rg_cli', sanitize_text_field($_POST['billing_rg_cli']));
    }

}

add_action('woocommerce_update_customer', 'record_custommer_edit');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.