Categorías

Campo cumpleaños usuarios

Categoria:

Wordpress, hooks, Registro, Woocommerce

Snippet:

 'date',
        'label'       => __( 'Fecha de nacimiento', 'woocommerce' ),
        'placeholder' => __( 'dd/mm/aaaa', 'woocommerce' ),
        'required'    => true,
    ), get_user_meta( get_current_user_id(), 'birthday_field', true ));
}
add_action( 'woocommerce_edit_account_form', 'action_woocommerce_edit_account_form' );

// Validate - my account
function action_woocommerce_save_account_details_errors( $args ){
    if ( isset($_POST['birthday_field']) && empty($_POST['birthday_field']) ) {
        $args->add( 'error', __( 'Please provide a birth date', 'woocommerce' ) );
    }
}
add_action( 'woocommerce_save_account_details_errors','action_woocommerce_save_account_details_errors', 10, 1 );

// Save - my account
function action_woocommerce_save_account_details( $user_id ) {  
    if( isset($_POST['birthday_field']) && ! empty($_POST['birthday_field']) ) {
        update_user_meta( $user_id, 'birthday_field', sanitize_text_field($_POST['birthday_field']) );
    }
}
add_action( 'woocommerce_save_account_details', 'action_woocommerce_save_account_details', 10, 1 );

// Add field - admin
function add_user_birtday_field( $user ) {
    ?>
        
        <label for="birthday_field"><span class="required">*</span><input type="date" name="birthday_field" value="ID )); ?>" class="regular-text" min='1900-01-01' max='2022-01-01' required/></label>
        <br /><br />
    ID );
    ?>
    <h3></h3>

    <table class="form-table">
        <tr>
            <th><label for="birthday_field"></label></th>
            <td>
                <input type="date" name="birthday_field" value="ID )); ?>" class="regular-text" min='1900-01-01' max='2022-01-01' required/>
            </td>
        </tr>
    </table>
    


Versiones:



Descripción:

https://www.cssigniter.com/how-to-add-a-custom-user-field-in-wordpress/



Code Snippets