David Jones
David Jones

Reputation: 10219

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?

Upvotes: 9

Views: 14855

Answers (1)

David Jones
David Jones

Reputation: 10219

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.

Upvotes: 14

Related Questions