Remove the input box when paying in Woocommerce – Learn WordPress from a to z

Tutorials 0 lượt xem

According to statistics, up to 70% of customers decide to abandon the shopping cart without paying. That is, they clicked the purchase button, but then left the site or canceled the cart without completing the payment. Among the reasons for this action, one reason is that the website’s checkout page is too cumbersome, requires too much and unnecessary content to be entered.

For example, on the following checkout page, the  Last  name box is not necessary, because guests can enter their full name in the  Name  box . In addition, if the website only sells goods in Vietnam, what is the need for  Country / Region  information ? So why not just leave it neat and tidy? In this article, I will show you how to remove such unnecessary fields. This will help the payment page look neater, customers work faster.

Remove the box to enter information when paying

To do this, you need code. The following code I refer to from the WooCommerce page itself and share it again for you to understand better.

First, open the  function.php file in Child Theme. Then paste this code at the bottom (or before the “?>” tag if applicable).

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_last_name']);
return $fields;
}
<div>
<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span>
</div>

Now go back to the payment page you have seen the box Last  name and Country / Region information has disappeared, right?

You can hide other fields, by adding the following code and editing it: unset($fields[‘billing’][‘billing_country’]);

You replace the 2 contents of billing and billing_country  with the corresponding information as follows:

  • billing
    • 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
  • shipping
    • shipping_first_name
    • shipping_last_name
    • shipping_company
    • shipping_address_1
    • shipping_address_2
    • shipping_city
    • shipping_postcode
    • shipping_country
    • shipping_state
  • account
    • account_username
    • account_password
    • account_password-2
  • order
    • order_comments

summary

Above is how to remove unnecessary fields when paying with WooCommerce. You can apply to any wordpress theme with this way. Good luck!

Bài viết liên quan