Xóa bỏ bớt trường không cần thiết ở trang thanh toán WooCommerce

Để xóa 1 trường trong phần thanh toán bạn chèn code dưới vào file functions.php trong theme bạn đang sử dụng.
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_state']);
return $fields;
}

Có các trường có thể xóa:

Mục Thanh toán (Billing): billing

  • Họ ( First Name)billing_first_name
  • Tên (Last Name)billing_last_name
  • Tên công ty (Company Name)billing_company
  • Địa chỉ (Address): billing_address_1
  • Địa chỉ 2billing_address_2
  • Tỉnh/Thành phố (Town/City)billing_city
  • Mã bưu điện (Postcode)billing_postcode
  • Quốc gia (Country)billing_country
  • Bang/Hạt (State)billing_state
  • Địa chỉ email (Email Address)billing_email
  • Số điện thoại (Phone)billing_phone

Mục Vận chuyển (Shipping)shipping

  • Họ ( First Name)billing_first_name
  • Tên (Last Name)billing_last_name
  • Tên công ty (Company Name)billing_company
  • Địa chỉ (Address): billing_address_1
  • Địa chỉ 2billing_address_2
  • Tỉnh/Thành phố (Town/City)billing_city
  • Mã bưu điện (Postcode)billing_postcode
  • Quốc gia (Country)billing_country
  • Bang/Hạt (State)billing_state

Mục Thêm thông tin ghi chú (Additional Infomation)order

  • Ô thêm ghi chúorder_comments

Mẫu dùng cho trang truyennghe.com chỉ dùng họ tên – sdt & email, còn lại xóa hết vì không cần thiết:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['shipping']['billing_first_name']);
unset($fields['shipping']['billing_last_name']);
unset($fields['shipping']['billing_company']);
unset($fields['shipping']['billing_address_1']);
unset($fields['shipping']['billing_address_2']);
unset($fields['shipping']['billing_city']);
unset($fields['shipping']['billing_postcode']);
unset($fields['shipping']['billing_country']);
unset($fields['shipping']['billing_state']);
unset($fields['order']['order_comments']);
return $fields;
}