=== BD Address Fields for WooCommerce ===
Contributors: shofiullah
Donate link: buymeacoffee.com/shofiullah
Tags: woocommerce, bangladesh, checkout, thana, upazila
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.2
Stable tag: 1.0.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

District and Thana/Upazila dropdowns for the WooCommerce checkout in Bangladesh. 64 districts, 620 thanas, including metropolitan areas.

== Description ==

Bangladeshi stores usually ask customers to type their thana or upazila into a
free text box. Customers spell it differently every time, delivery staff have
to guess, and couriers reject addresses they cannot match.

This plugin replaces that text box with a dropdown. The customer picks a
**District**, and the **Thana / Upazila** list updates instantly to show only
the areas inside that district.

= Complete, current data =

* All 64 districts, using the official English spellings adopted in 2018:
  Chattogram, Cumilla, Barishal, Jashore and Bogura.
* 620 thanas and upazilas in total.
* Metropolitan police thanas are included alongside rural upazilas for Dhaka,
  Chattogram, Khulna, Rajshahi, Sylhet, Gazipur, Narayanganj, Barishal and
  Rangpur. A customer in Mirpur, Uttara, Panchlaish or Sonadanga can select
  their actual area rather than the nearest rural upazila.

= Built for real stores =

* Works on the checkout, My Account address forms, and the cart shipping
  calculator.
* Nothing is preselected. The district field prompts "Please select district"
  and the thana field prompts "Please select district first" until a district
  is chosen, then "Please select thana".
* Districts WooCommerce would otherwise prefill from your shop base address or
  IP geolocation are cleared, so a customer outside your own city is never
  quoted the wrong delivery charge because they skimmed past a guessed field.
  A returning customer's own saved address is left untouched.
* Declares compatibility with WooCommerce High-Performance Order Storage
  (HPOS) and the Cart and Checkout Blocks features.
* Adds no database tables, no settings page, and no admin bloat. The data ships
  as plain PHP arrays, so there are no extra queries on the checkout.
* Around 3 KB of gzipped data is added to the checkout page, loaded only where
  address fields are actually rendered.

= Data sources =

District and thana names are cross-checked against the Dhaka Metropolitan
Police station directory and public Bangladesh administrative division records.

== Installation ==

1. Go to **Plugins > Add New > Upload Plugin** and upload the ZIP file.
2. Activate the plugin.
3. Make sure Bangladesh is enabled under **WooCommerce > Settings > General >
   Selling location(s)**.

There is nothing to configure. Open your checkout page and the District and
Thana fields will be in place.

== Frequently Asked Questions ==

= WooCommerce keeps prefilling my own city. Can I keep that behaviour? =

By default the plugin clears a district or thana that WooCommerce guessed from
the shop base address or IP geolocation, so both dropdowns open on their
prompt. Addresses your logged-in customers saved themselves are never cleared.

To go back to WooCommerce's guess, add:

`add_filter( 'bdaf_clear_prefilled_address', '__return_false' );`

This works regardless of what **WooCommerce > Settings > General > Default
customer location** is set to, so you do not have to change that setting.

= Can I keep WooCommerce's own district names? =

The plugin corrects five district labels. To keep the WooCommerce core labels
instead, add:

`add_filter( 'bdaf_override_core_states', '__return_false' );`

District codes are never changed either way, so shipping zones are safe.

= The Thana field still shows as a text box =

Check that Bangladesh is listed in your allowed selling or shipping countries.
The dropdown only appears for countries that have matching data files in the
plugin's `states` and `places` folders.

= Does this work with the block based Checkout? =

The cascading dropdown is built for the classic shortcode checkout. On the
block checkout the plugin steps aside and WooCommerce's standard fields are
used, so nothing breaks.

= A thana in my area is missing or spelled differently =

Edit `places/bd.php` and adjust the array for that district. The keys match the
district codes in `states/bd.php`. Please also open an issue so the correction
can ship for everyone.

= Will this change my existing orders? =

No. Orders keep whatever address was stored when they were placed. The plugin
only changes how the field is displayed from now on.

== Screenshots ==

1. District and Thana dropdowns on the WooCommerce checkout.
2. Selecting a district instantly filters the Thana list.
3. The same fields on the My Account address form.

== Changelog ==

= 1.0.0 =
* Initial release.
* 64 districts and 620 thanas and upazilas.
* Metropolitan thanas included for nine city districts, so customers in Mirpur,
  Uttara, Panchlaish or Sonadanga can select their own area.
* District codes match those used by WooCommerce core, so shipping zones and
  saved orders keep working. Five district labels are corrected: the trailing
  spaces on Faridpur and Manikganj are removed, and Nawabganj, Netrakona and
  Jhalokati become Chapainawabganj, Netrokona and Jhalakathi.
* No value is preselected in either dropdown. The customer is prompted to
  choose a district, then a thana.
* Districts and thanas prefilled by WooCommerce from the shop base address or
  IP geolocation are cleared, while saved customer addresses are preserved.
* WooCommerce HPOS and Cart/Checkout Blocks compatibility declared.

== Upgrade Notice ==

= 1.0.0 =
Initial release.

== Credits ==

This plugin is a derivative work distributed under the GNU General Public
License v2 or later.

* The states and places architecture, and the cascading select script, come
  from the WC City Select plugin, https://wordpress.org/plugins/wc-city-select/
* The Bangladesh adaptation, "Thana/Upazila Dropdown for Woocommerce
  [Bangladesh]", is by Md Rasel Khan,
  https://github.com/immdraselkhan/Thana-Upazila-Dropdown-for-Woocommerce-Bangladesh
