Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce error when removing billing fields: "Please enter an address to continue."

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?

like image 249
David Jones Avatar asked Oct 10 '17 16:10

David Jones


People also ask

How do I remove a billing field in WooCommerce?

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 ...

How do I enable billing and shipping address in WooCommerce?

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.

How do I find my billing address in WooCommerce?

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();


1 Answers

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.

like image 137
David Jones Avatar answered Nov 15 '22 20:11

David Jones