1, Bỏ các trường không cần thiết trong trang checkout (Thanh toán)
1 2 3 4 5 6 7 8 9 10 |
function neartech_woocommerce_remote_billing_fields( $fields ) { unset( $fields['billing_last_name'] ); unset( $fields['billing_address_2'] ); unset( $fields['billing_city'] ); unset( $fields['billing_postcode'] ); unset( $fields['billing_state'] ); $fields['billing_email']['class'] = array( 'form-row-wide' ); return $fields; } add_filter( 'woocommerce_billing_fields', 'neartech_woocommerce_remote_billing_fields' ); |
2, Bỏ bắt buộc nhập và xóa trường billing_address_2 và shipping_address_2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
add_filter('woocommerce_checkout_fields', 'unrequire_address_2_checkout_fields' ); function unrequire_address_2_checkout_fields( $fields ) { $fields['billing']['billing_address_2']['required'] = false; $fields['shipping']['shipping_address_2']['required'] = false; return $fields; } // Remove billing address 2 from Checkout for WooCommerce add_filter('cfw_get_billing_checkout_fields', 'remove_billing_address_2_checkout_fields', 100, 3); function remove_billing_address_2_checkout_fields( $fields ) { unset($fields['billing_address_2']); return $fields; } // Remove shipping address 2 from Checkout for WooCommerce add_filter('cfw_get_shipping_checkout_fields', 'remove_shipping_address_2_checkout_fields', 100, 3); function remove_shipping_address_2_checkout_fields( $fields ) { unset($fields['shipping_address_2']); return $fields; } |
3, Ẩn các title field và thêm placeholder cho các trường trong trang Checkout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
add_filter('woocommerce_checkout_fields','custom_wc_checkout_fields_no_label'); function custom_wc_checkout_fields_no_label($fields) { foreach ($fields as $category => $value) { foreach ($fields[$category] as $field => $property) { unset($fields[$category][$field]['label']); } } return $fields; } add_filter( 'woocommerce_checkout_fields' , 'override_billing_checkout_fields', 20, 1 ); function override_billing_checkout_fields( $fields ) { $fields['billing']['billing_first_name']['placeholder'] = 'Họ và tên'; $fields['billing']['billing_phone']['placeholder'] = 'Điện thoại'; $fields['billing']['billing_address_1']['placeholder'] = 'Địa chỉ'; $fields['billing']['billing_email']['placeholder'] = 'Địa chỉ Email'; return $fields; } |
4, Sắp xếp thứ tự hiển thị các trường trong trang Checkout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
add_filter("woocommerce_checkout_fields", "new_order_fields"); function new_order_fields($fields) { $order = array( "billing_first_name", "billing_phone", "billing_address_1", "billing_email" ); foreach( $order as $field ) { $ordered_fields[$field] = $fields["billing"][$field]; } $fields["billing"] = $ordered_fields; return $fields; } |
5, Danh sách các trường trong trang checkout
a, Các trường Billing
1 2 3 4 5 6 7 8 9 10 11 |
billing_first_name billing_last_name billing_company billing_address_1 billing_address_2 billing_city billing_postcode billing_country billing_state billing_email billing_phone |
b, Các trường Shipping
1 2 3 4 5 6 7 8 9 |
shipping_first_name shipping_last_name shipping_company shipping_address_1 shipping_address_2 shipping_city shipping_postcode shipping_country shipping_state |
c, Các trường account
1 2 3 |
account_username account_password account_password-2 |
d, Các trường thuộc order
1 |
order_comments |
6, Thuộc tính của các trường checkout
1 2 3 4 5 6 7 8 |
type – type of field (text, textarea, password, select) label – label for the input field placeholder – placeholder for the input class – class for the input required – true or false, whether or not the field is require clear – true or false, applies a clear fix to the field/label label_class – class for the label element options – for select boxes, array of options (key => value pairs) |
Neartech xin trân trọng cảm ơn bạn đã quan tâm bài viết này! Nếu bạn gặp khó khăn gì hãy để lại comment ở bên dưới, nếu có thể mình sẽ giúp đỡ bạn!