Customize Woocommerce Registration!

0

Personal I have a project where I need to customize the registration form of Woocommerce, it already has email and password. However 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? Thanks!

    
asked by anonymous 01.03.2018 / 19:24

1 answer

0

You can use this code in the functions 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 write 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');
    
01.10.2018 / 17:01