/*
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.16.1
Requires at least:    5.0.0
Requires PHP:         5.6.20
WC requires at least: 4.4.0
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.
***************/

// code trang thanh toán
add_filter( 'woocommerce_checkout_fields' , 'custom_checkout_form' );
function custom_checkout_form( $fields ) {
   unset($fields['billing']['billing_postcode']); //Ẩn postCode
 unset($fields['billing']['billing_state']); //Ẩn bang hạt
   unset($fields['billing']['billing_country']);// Ẩn quốc gia
    unset($fields['billing']['billing_address_2']); //billing_company
    unset($fields['billing']['billing_company']);
   unset($fields['billing']['billing_last_name']);
   unset($fields['billing']['order_comments']);// Ẩn quốc gia
   unset($fields['billing']['billing_city']); //Ẩn select box chọn thành phố
 unset($fields['billing']['billing_email']); //Ẩn select box chọn thành phố
     $fields['billing']['billing_first_name']['placeholder'] = "Họ và tên";
     $fields['billing']['billing_phone']['placeholder'] = "Số điện thoại";
    return $fields;
}
function custom_checkout_field_label( $fields ) {
    $fields['address_1']['label'] = 'Địa chỉ giao sản phẩm';
    $fields['first_name']['label'] = 'Tên';
    return $fields;
}
add_filter( 'woocommerce_default_address_fields', 'custom_checkout_field_label' );

// Bỏ bắt buộc điền mail trong trang thanh toán

add_filter( 'woocommerce_billing_fields', 'filter_billing_fields', 20, 1 );
function filter_billing_fields( $billing_fields ) {
    // Only on checkout page
    if( ! is_checkout() ) return $billing_fields;

	$billing_fields['billing_email']['required'] = false;
	$billing_fields['billing_company']['required'] = false;
	$billing_fields['billing_city']['required'] = false;
	$billing_fields['billing_address_2']['required'] = false;
	$billing_fields['billing_state']['required'] = false;
	$billing_fields['billing_postcode']['required'] = false;
	$billing_fields['billing_last_name']['required'] = false;
    return $billing_fields;
}

// thêm hình ảnh sản phẩm vào trang thanh toán
add_filter( 'woocommerce_cart_item_name', 'itcodewp_product_image_on_checkout', 10, 3 );
 
function itcodewp_product_image_on_checkout( $name, $cart_item, $cart_item_key ) {
     
    /* Return if not checkout page */
    if ( ! is_checkout() ) {
        return $name;
    }
     
    /* Get product object */
    $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
 
    /* Get product thumbnail */
    $thumbnail = $_product->get_image();
 
    /* Add wrapper to image and add some css */
    $image = '<div class="ts-product-image">'
                . $thumbnail .
            '</div>'; 
 
    /* Prepend image to name and return it */
    return $image . $name;
}
// end thêm hình ảnh sản phẩm vào trang thanh toán

<style>
.woocommerce-checkout .ts-product-image {
    width: 52px;
    height: 45px;
    padding-right: 7px;
    vertical-align: middle;
    float: left;
}