I've removed billing fields on the WooCommerce checkout page by adding the following lines to functions.php
:
add_filter("woocommerce_checkout_fields", "remove_billing_fields");
function remove_billing_fields($fields) {
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_email"]);
unset($fields["billing"]["billing_phone"]);
return $fields;
}
This does remove the billing fields and leaves the shipping fields in-tact, as desired. However, now I get an error on checkout:
Please enter an address to continue.
However, all shipping fields are filled out. The request is being sent via AJAX (/shop/checkout?wc-ajax=checkout
). Upon inspecting the request, I see the following fields are being sent:
billing_email:[email protected]
shipping_first_name:John
shipping_last_name:Doe
shipping_address_1:123 Easy St
shipping_address_2:
shipping_country:US
shipping_state:NY
shipping_city:New York
shipping_postcode:12345
billing_phone:123-456-7890
payment_method:stripe
wc-stripe-payment-token:abc123
_wpnonce:abc123
_wp_http_referer:/shop/checkout
Note that the request does go through when billing fields are set, so I believe everything else is set up correctly. Any ideas why this error is being thrown?
Go to the WooCommerce tab in your WordPress dashboard. Click on Checkout and then on the Billing tab. You'll see a list of all the fields you can hide so just activate the disable option on the field you want to remove. After that, you can go to the Shipping and Additional tabs and disable the fields you want to delete ...
In WooCommerce->Settings->Shipping Tab, find shipping options and make sure the Shipping Destination is set to 'Default to customer billing address' or 'Default to customer shipping address'. If it is set to 'Force shipping to the customer billing address', the shipping fields will not be displayed.
You can fetch billing address by using WC_Order object and get_billing_address() from order id. Use the following code to fetch billing address from order ID. $order = new WC_Order( $order_id ); $billing_address=$order->get_billing_address();
I found that although I can hide the billing_country
field, it is required in order to calculate taxes and shipping, even if WooCommerce is configured to use the shipping fields by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With