mercredi 3 mars 2021

Add extra checkboxes in Woocommerce user register form and saving / showing if are checked in the backend as user extra data

I would like to show in the backend, when seeing the user detail if the checkboxes were selected when the user was created, here is the code that helped me to implement the extra checkboxes in the register form.

function woocommerce_edit_my_account_page() {
    return apply_filters( 'woocommerce_forms_field', array(
        'woocommerce_my_account_page' => array(
            'type'        => 'checkbox',
            'label'       => __( 'Soy mayor de 18'),
            'required'    => true,
        ),
        array(
            'type'        => 'checkbox',
            'label'       => __( 'Le doy permiso de usar mis datos'),
            'required'    => true,
        ),
    ) );
}
function edit_my_account_page_woocommerce() {
    $fields = woocommerce_edit_my_account_page();
    foreach ( $fields as $key => $field_args ) {
        woocommerce_form_field( $key, $field_args );
    }
}
add_action( 'woocommerce_register_form', 'edit_my_account_page_woocommerce', 15 );



Aucun commentaire:

Enregistrer un commentaire