1BANNER 123
4.9/5 - (58 bình chọn)

Hôm nay mình sẽ chia sẻ cách để có thể remove các field có trong checkout của woocommerce.

Đầu tiên các bạn mở file function.php lên và tạo một function có tên gọi là remove_field_checkout().

sau đó hook nó vào woocommerce_checkout_fields.

Đoạn code sẽ có nội dung như sau:

add_filter( 'woocommerce_checkout_fields' , 'remove_field_checkout' );
function remove_field_checkout( $fields ) {
 
    return $fields;
}

Các bạn chỉ cần truyền vào đó field mà mình cần loại bỏ đi là được. Dưới đây là danh sách các field hiện đang có trong checkout.

Unset các field không cần thiết trong checkout

unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
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['billing']['billing_phone']);
unset($fields['order']['order_comments']);
unset($fields['billing']['billing_email']);
unset($fields['account']['account_username']);
unset($fields['account']['account_password']);
unset($fields['account']['account_password-2']);

File function hoàn chỉnh của bạn sẽ có dạng như sau:

Function hoàn chỉnh của remove field trong checkout

Di chuyển vị trí của các field trong checkout của woocommerce

Để có thể thực hiện được việc này các bạn sử dụng các đoạn code sau vào function remove_field_checkout() trên là được nhé:

$fields['billing']['billing_first_name']['priority'] = 1;

Trong đó thì [‘billing_first_name’] là tên field mà mình chọn, [‘priority’] là vị trí (sự ưu tiên hiển thị).

Ở đây priority = 1 nên nó sẽ ở vị trí cao nhất.

và đây là kết quả.

Field name đã di chuyển lên vị trí đầu tiên

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *