/*
Theme Name:           Flatsome
Theme URI:            http://flatsome.uxthemes.com
Author:               UX-Themes
Author URI:           https://uxthemes.com
Description:          Multi-Purpose Responsive WooCommerce Theme
Version:              3.19.11
Requires at least:    6.4
Requires PHP:         7.4
WC requires at least: 8.3
Text Domain:          flatsome
License:              https://themeforest.net/licenses
License URI:          https://themeforest.net/licenses
*/


/***************
All custom CSS should be added to Flatsome > Advanced > Custom CSS,
or in the style.css of a Child Theme.
***************/
// Thêm trường Họ tên vào form đăng ký WooCommerce
add_action( 'woocommerce_register_form_start', function() {
    ?>
    <p class="form-row form-row-wide">
        <label for="reg_full_name">Họ và tên *</label>
        <input type="text" class="input-text" name="full_name" id="reg_full_name" value="<?php if ( ! empty( $_POST['full_name'] ) ) echo esc_attr( wp_unslash( $_POST['full_name'] ) ); ?>" />
    </p>
    <?php
});

// Lưu họ tên vào tài khoản
add_action( 'woocommerce_created_customer', function( $customer_id ) {
    if ( isset( $_POST['full_name'] ) ) {
        update_user_meta( $customer_id, 'full_name', sanitize_text_field( $_POST['full_name'] ) );
    }
});
