=== RaCar Checkout Manager for Brazilian Stores ===
Contributors: rafacarvalhido
Donate link: https://linknabio.gg/rafa_carvalhido_wp
Tags: WooCommerce, Brazil, CPF, CNPJ, Checkout
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 0.10.7
WC requires at least: 9.0
WC tested up to: 11.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Adds brazil's input fields to checkout & more.
Plugin p/ lojas brasileiras com CPF, CNPJ e outros campos ao checkout, auto-preenchimento de endereços.

== Description ==

**RaCar Checkout Manager for Brazilian Stores** is a powerful WooCommerce plugin designed specifically for Brazilian stores. It enhances the WooCommerce checkout experience by adding essential fields like CPF, CNPJ, RG, and more and allowing control of all WooCommerce fields. Additionally, it includes an address autofill feature that uses CEP (Brazilian postal codes) to automatically populate address fields, saving time and improving accuracy.

O **Gerenciador de Checkout RaCar para Lojas Brasileiras** é um poderoso plugin para WooCommerce desenvolvido especificamente para lojas no Brasil. Ele aprimora a experiência de finalização de compra no WooCommerce, adicionando campos essenciais como CPF, CNPJ, RG e outros, além de permitir o controle de todos os campos do WooCommerce. Adicionalmente, inclui um recurso de preenchimento automático de endereços que utiliza o CEP  para preencher automaticamente os campos de endereço e bloquenado-os (à escolha do admin), economizando tempo e aumentando a precisão.

### Key Features:

- **CPF, CNPJ, and RG Fields:** Add and validate these essential fields for Brazilian customers.
- **Address Autofill:** Automatically fill in address fields based on the CEP entered by the customer.
- **Customizable Checkout Fields:** Enable, disable, or customize checkout fields to suit your store's needs.
- **Input Masks:** Add input masks for CPF, CNPJ, and cellphone fields for better user experience.
- **WooCommerce HPOS Compatibility:** Fully compatible with WooCommerce's High-Performance Order Storage (HPOS).
- **Admin Interface:** Modern and intuitive admin interface for managing settings.
- **Translation Ready:** Fully localized and ready for translation.

This plugin is free and always will be. If it saves you time, consider [buying me a coffee](https://linknabio.gg/rafa_carvalhido_wp) to support its development.

- **Campos CPF, RG, CNPJ, IE, número da residência, bairro e telefone:** Adiciona e valida esses campos essenciais para clientes brasileiros.
- **Preenchimento automático de endereço:** Preenche automaticamente os campos de endereço com base no CEP inserido pelo cliente.
- **Bloqueio de campos de endereço:** Ao preencher os campos de endereço, pode bloqueá-los ao comando do admin.
- **Campos do checkout personalizáveis:** Habilite, desabilite ou personalize os campos de finalização de compra para atender às necessidades da sua loja.
- **Máscaras de entrada:** Adiciona máscaras de entrada (pontos e traços) para os campos CPF, CNPJ, CEP e celular para uma melhor experiência do usuário.
- **Compatibilidade com WooCommerce HPOS:** Totalmente compatível com o High-Performance Order Storage (HPOS) do WooCommerce.
- **Interface administrativa:** Interface administrativa moderna e intuitiva para gerenciar as configurações.
- **No seu idioma:** Já vem traduzido para o pt-BR, mas você pode mudar qualquer texto que aparece para o usuário.

Este plugin é gratuito e sempre será. Se ele economizar seu tempo, considere me [oferecer um café](https://linknabio.gg/rafa_carvalhido_wp) para apoiar o desenvolvimento deste e outros plugins.

== External Services ==

This plugin connects to external APIs to obtain address information based on Brazilian postal codes (CEP), which is needed to autofill address fields during checkout and registration. These services are used only when the user enters a CEP during checkout and the autofill feature is enabled.

### BrasilAPI (Primary Service)
The plugin sends the user's postal code (CEP) to BrasilAPI when the user enters a valid CEP in the address field 'postcode'.
This service is provided by "BrasilAPI": https://brasilapi.com.br/docs (terms of use and privacy policy available on their website).

**What is it?**
BrasilAPI is a free public API that provides Brazilian address data based on postal codes (CEP).

**What data is sent?**
- Only the CEP (postal code) is sent via a GET request to `https://brasilapi.com.br/api/cep/v2/{cep}` (e.g., `https://brasilapi.com.br/api/cep/v2/01234567`).
- No personal user data (name, email, order details, or IP address) is transmitted.
- Requests are made only when the user enters a valid CEP and triggers the autofill feature (via JavaScript on the frontend).

**When is it used?**
- When a customer enters a CEP in the billing or shipping address field during checkout.
- Only if the address autofill feature is enabled in the plugin settings (Tab 2: Autofill Addresses).

**What data is returned?**
- Street name (logradouro)
- Neighborhood (bairro)
- City (cidade)
- State (uf)

**Terms and Documentation:**
- BrasilAPI Terms of Service: https://brasilapi.com.br/#termos-de-uso
- BrasilAPI Documentation: https://brasilapi.com.br/docs

### ViaCEP (Fallback Service)

If BrasilAPI does not return a usable address (network error, HTTP error, invalid JSON, or CEP not found), the plugin tries **ViaCEP** once as a secondary source.

The plugin sends only the same Brazilian postal code (CEP) in a GET request to `https://viacep.com.br/ws/{cep}/json/` (see [ViaCEP](https://viacep.com.br/)). ViaCEP is a widely used public CEP lookup service in Brazil. Formal terms of use are not published as clearly as some larger APIs; the plugin documents this connection here for transparency and WordPress.org compliance.

**What data is sent?**
- Only the CEP digits in the URL path (same scope as BrasilAPI).
- No personal user data (name, email, order details, or IP address) is transmitted by the plugin.

**When is it used?**
- Only after BrasilAPI fails or returns no valid address for that CEP.
- Only when autofill is enabled and the customer triggers a CEP lookup as described above.

### Data Handling

- **No data storage:** The plugin does not store or track any data beyond the single request to the API.
- **Optional feature:** The address autofill integration is optional and can be disabled in the plugin settings (Tab 2: Autofill Addresses).
- **Fallback mechanism:** The plugin tries BrasilAPI first, then ViaCEP. If neither service returns a valid address, the checkout continues with manual entry without fatal errors.
- **User control:** Users can disable the autofill feature at any time through the plugin settings.

=== Data Transmission ===
Data sent: Only the Brazilian postal code (CEP) entered by the user.
When: Every time a user enters or modifies a CEP field (postcode) during WooCommerce checkout or My Account registration.
Conditions: Only when the user manually enters a CEP value. No data is sent if the field is left empty.
Purpose: To automatically populate address fields (street, neighborhood, city, state) based on the provided CEP.
Storage: The CEP and returned address data are stored locally in the user's browser session and WooCommerce order/customer data. Responses come from BrasilAPI when available, otherwise from ViaCEP; third-party APIs do not retain that payload beyond normal HTTP handling.

== Installation ==

1. Upload the plugin files to the `/wp-content/plugins/racar-checkout-manager-for-brazilian-stores` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress.
3. Navigate to **RaCar Plugins > Gerenciador de Campos para Lojas Brasileiras** in the WordPress admin menu to configure the settings.
4. Customize the checkout fields and enable the address autofill feature as needed.

== Frequently Asked Questions ==

= Does this plugin work with WooCommerce HPOS? =

Yes, the plugin is fully compatible with WooCommerce's High-Performance Order Storage (HPOS).

= How does the address autofill feature work? =

The plugin uses Brazilian CEPs (postal codes) to fetch address data: it calls BrasilAPI first, and uses ViaCEP as a fallback if BrasilAPI does not return a valid address. This data is then used to automatically populate the address fields during checkout.

= Can I disable specific checkout fields? =

Yes, you can enable or disable individual fields like CPF, CNPJ, RG, and more from the plugin's settings page.

= Is this plugin translation-ready? =

Yes, the plugin is fully localized and ready for translation into other languages.

= Does this plugin support input masks? =

Yes, you can enable input masks for fields like CPF, CNPJ, and cellphone to improve the user experience.

= Can I disable the address autofill feature? =

Yes, you can disable the autofill feature entirely from the plugin settings (Tab 2: Autofill Addresses). When disabled, no external API calls are made.

= Does uninstall remove customer CPF/CNPJ or order data? =

No. Uninstall removes plugin options and logs an audit entry when WooCommerce logging is enabled, but **user meta** (for example `billing_cpf`) and **order meta** are preserved so fiscal history and ERP integrations remain intact.

= Does order meta stay compatible with Brazilian Market-style integrations (shipping carriers, ERPs)? =

Yes. From 0.6.1 onward, person type is stored on orders and customers as **1** (individual) / **2** (company), matching **Brazilian Market on WooCommerce**. When checkout ships to the billing address (no separate shipping address), **number** and **neighborhood** are mirrored into shipping meta (`_shipping_number`, `_shipping_neighborhood`) when those shipping fields would otherwise be empty—matching what many Brazilian carriers expect.

Third-party plugins that read the same meta keys (for example **Loggi**, **Correios Automático Infix**, **Melhor Envio** buyer payloads, **Link Nacional** improved shipping calculator conventions) continue to work without Brazilian Market installed. **Melhor Envio** may still show its own admin notice until their plugin explicitly recognizes RaCar—configure shipping fields here regardless.

= How do I control field width on a checkout row? =

In **Checkout Fields (Tab 1)**, open a field’s settings (cog) and choose **Row layout**: **Full row** (one line), **Left column**, or **Right column**. **Priority** controls vertical order only. On classic checkout this maps to WooCommerce `form-row-*` classes; on Checkout Block it maps to flex width rules generated by the plugin.

= Why did checkout columns look broken after activating the plugin? =

Classic checkout rows often use `form-row-first` / `form-row-last` together with theme CSS floats. The plugin keeps those WooCommerce classes but changes **which rows are visible** (PF/PJ toggles) and interacts with WooCommerce scripts that can **reassign row classes** when country or locale rules change (the plugin also restores your configured postcode row classes after `country_to_state_changing`). That can misalign float pairs even though class names match WooCommerce defaults.

= How do I fix overlapping checkout columns safely? =

In **Checkout Fields (Tab 1)**, enable **Classic Checkout Layout (Float Compatibility) → Recover floated checkout columns**. It is **off by default** so normal themes are unaffected; when enabled, it outputs a **checkout-only** rule (`clear: both` on `form-row-first`) with exclusions for wide rows and the plugin’s three-column helpers. Test checkout with your theme after enabling; disable again if anything looks worse.

= How should I verify layout after changing float compatibility? =

Use the classic checkout page (shortcode checkout). With the option **off**, confirm billing/shipping look as before. Turn it **on** only on stores that showed overlap; recheck billing, shipping, switching PF/PJ (when applicable), and changing country if customers can. Storefront is a good baseline; themes that rely heavily on floats benefit most.

= On phones my checkout fields stack full width, but I want the same row layout as desktop. What can I do? =

**Classic checkout:** In **Checkout Fields (Tab 1)** → **Classic Checkout Layout (Float Compatibility)**, enable **Preserve two-column row layout on small screens** (default **off**). It applies **classic shortcode checkout only** (not block checkout): under `max-width: 768px` it restores two-column widths for fields set to **Left column** / **Right column** when themes stack everything full width.

**Block checkout:** Below ~700px container width, WooCommerce and this plugin stack address fields full width by design (better mobile UX). Adjust **Row layout** on desktop; mobile stacking is expected.

= What should I test before enabling block checkout on production? =

Use this go/no-go checklist after enabling **Block checkout support** on Tab 1 (test on your store’s block checkout URL):

* **Persistence:** Guest and logged-in orders; confirm `_wc_billing/rbsmhao/*`, `_wc_shipping/rbsmhao/*`, `billing_*`, and `_billing_*` meta on the order.
* **Validation:** Invalid CPF/CNPJ blocks checkout; optional fields do not block when empty.
* **Display:** Order admin, order emails, My Account overview, and WooCommerce REST order payload show the same Brazilian data (legacy and Blocks meta).
* **PF/PJ:** Toggle shows/hides the correct field groups; server validation matches the selected person type.
* **Conflicts:** With **Brazilian Checkout Toolkit** active, RaCar block registration stays off and an admin notice explains why.
* **Mobile UX:** Masks do not jump the caret while typing CPF/CNPJ/phone on iOS/Android.
* **Rollback:** Disable **Block checkout support** or add `add_filter( 'rbsmhao_disable_blocks_checkout_support', '__return_true' );` — classic checkout and existing orders must remain intact.

== Screenshots ==

1. **Checkout Fields Settings** - Customize the fields displayed at checkout.
2. **Address Autofill Settings** - Enable or disable the address autofill feature.
3. **Frontend Display** - Manage settings like priority, row layout (full row / left / right column), label, placeholder, etc. Blocked fields after CEP search.

== Changelog ==

= 0.10.7 - 2026-09-07 =
* Block checkout: keep Address line 2 (Complemento) layout stable per Tab 1 — hide the “+ Add” control when the field is disabled; auto-expand then hide “+ Add” when enabled and optional; leave WooCommerce alone when the field is required.

= 0.10.6 - 2026-09-07 =
* company_as_name: copy company into first_name only and clear last_name (classic + Blocks + order persistence).
* Fix: stop reading shipping phone via get_meta( `_shipping_phone` ) on order emails / My Account / admin (wc_doing_it_wrong); harden LegacyMetaBridge to use WC getters for core address props.
* Classic checkout stores no longer boot Blocks checkout integration (registrar/Store API hooks) unless the store or request uses Blocks checkout; moved LegacyMetaBridge out of the Blocks namespace.

= 0.10.5 - 2026-09-07 =
* My Account registration: stop printing `account_username` / `account_password` when WooCommerce (or a theme override such as Woodmart) already shows `username` / `password` for manual account creation; skip ROAPC required checks for those keys outside checkout so validation still uses WC’s native POST fields.

= 0.10.4 - 2026-09-06 =
* Compatibility: remove native PHP union types (`array|false`, `array|bool`) from Blocks registrar/schema helpers that caused a fatal parse error on hosts whose request/CLI PHP is older than 8.0; refuse to boot below PHP 8.0 with an admin notice instead of a white-screen parse error.

= 0.10.3 - 2026-09-06 =
* Tab 4 / ROAPC: renamed option `all_fields_wide` to `registration_fields_wide` (existing installs migrate automatically and keep their saved value); new installs default to on.

= 0.10.2 - 2026-09-05 =
* Tab 3: enabling “Use CPF or CNPJ as login username” (`cpf_login`) automatically enables and locks One Account Per CPF/CNPJ (`oapc_enabled`); sanitization forces `oapc_enabled` when `cpf_login` is on.

= 0.10.1 - 2026-09-03 =
* Block checkout (Tab 1): fix Shipping Address left/right row pairing so adjacent half-width fields (country+postcode, neighborhood+number, city+state) stay on the same row in admin and on the storefront.
* Block checkout (Tab 1): swapping Left/Right on a paired field now flips the partner and keeps both cards on the same row; drag-to-dashed-slot beside an unpaired left column works again.
* Block checkout: sync shared shipping/billing address twins (`row_layout` / `priority`) on load and save; hide duplicate native address cards under Billing Address (configure them under Shipping Address).

= 0.10.0 - 2026-09-02 =
* Performance: memoize `get_settings()` per request; scope `rbsmhao-input-masks` to checkout/account screens; add `defer` strategy to frontend scripts; scope Store API checkout merge hook.
* Cleanup: remove dead admin hook/methods, unused autofill CSS, unregistered order-notes filters; fix `plugin_action_links_{basename}`; simplify admin tab navigation (no nonce on tab switch).
* DRY: ROAPC CPF validation delegates to shared `DocumentValidator`.
* Structure: `WooCommerceBlocksAdapter` for WC Blocks internals; PSR-4 autoloader for `includes/Checkout/`.
* Docs: regression matrix updated; uninstall preserves user/order meta documented.

= 0.9.6 - 2026-08-27 =
* Tab 1: new global option **Always apply Brazilian checkout on the frontend** (enabled by default). When on, Brazilian fields, layout, validation, masks, and CEP autofill apply regardless of the selected country; when off, behavior matches the previous BR-only gate.
* Centralized gate in `CheckoutCountryGate` (`should_apply_brazilian_rules`) and propagated to classic checkout, block checkout, locale, persistence, and frontend JS.

= 0.9.5 - 2026-08-27 =
* Classic checkout: PF/PJ toggles now target billing field rows by ID (company, CPF/CNPJ, etc.) with the same company_as_name behavior as Block checkout — hide/show names, restore names when returning to PF, copy company into first/last on place order, and persist names on the order server-side.

= 0.9.4 - 2026-08-27 =
* Block checkout: Documents (identity) section renders first — before contact, shipping, and billing. Tab 1 Block field grid matches that section order.

= 0.9.3 - 2026-08-27 =
* Bootstrap: initialize the plugin once on `plugins_loaded` (removed the immediate `start_all_engines()` call that ran before WooCommerce was loaded).
* Autofill: start the CEP module immediately when the loader is constructed during `plugins_loaded` (avoids a nested `plugins_loaded` hook that never fired).
* Checkout context: detect block checkout/cart from the current page content only (no store-wide `is_*_block_default()` fallback); order-pay / thank-you and classic shortcode pages no longer inherit the store block-checkout page.

= 0.9.2 - 2026-08-27 =
* WordPress.org conformity: `Requires at least` raised to 6.5 (`.l10n.php` translations); `WC tested up to` raised to 11.0.
* Removed development `prompt-bling.txt` from the plugin distribution folder (kept in project docs).
* PHPCS: aligned nonce-ignore comment on `CheckoutCountryGate` to the flagged `$_POST` line.
* Readme: removed local development URL from the block checkout go/no-go FAQ (Plugin Check `localhost` rule).

= 0.9.1 - 2026-08-27 =
* Security: stop storing `account_password` / `account_username` in usermeta on registration; remove legacy plaintext password meta when present.
* Security: escape late on admin order customer HTML (`wp_kses_post`) and escape dynamic labels in checkout notices.
* Security: CEP REST proxy now caches responses, shortens upstream timeout, and rate-limits by IP; HEAD requests are allowed.
* Block checkout: CEP autofill works via a dedicated Blocks script (classic script unchanged); CEP input mask applied to billing/shipping postcode.
* WordPress.org hygiene: moved `prompt-bling.txt` out of the plugin folder; shortened long upgrade notices; sanitized `$_SERVER` reads in block validator; PHPCS ignores aligned.

= 0.9.0 - 2026-08-24 =
* Tab 1 visual field grid: drag fields within a section to set checkout order. The plugin writes existing `priority` values (copied to `index` on Block checkout). Shipping Address order also updates matching native billing address fields (the Checkout Block shares one address form). Documents, contact, and order notes keep their own order.
* Tab 1 visual field grid: cards preview Full / Left / Right row layout (flex wrap, half-width columns, line break, and spacer) so admin order matches the storefront. Classic Checkout is also sortable; the Placeholder field stays on Classic text fields only. Block still mirrors shipping/billing twins.
* Block checkout: contact password and username follow the same row-layout width as other contact fields (`account_password` → `password`, `account_username` → `username`).
* Block checkout: Tab 1 input height and line-height now apply to WooCommerce Blocks text inputs (including password). Classic `input-text` dimension CSS is not loaded on block checkout.
* Block checkout: leftover hidden document-field shells and extra flex-breaks no longer create empty rows under company or Documents. Vertical gap uses the form `row-gap` (same as sibling rows); person type (full) does not insert an extra break before the next Documents row. Person-type/gender select height follows the sibling text-input height.
* Block checkout: order notes (`order_comments`) display as a full-width textarea. WooCommerce additional checkout fields only support `text`/`select`/`checkbox`, so the native order-note block stays hidden when RaCar manages notes and the Tab 1 field is presented as a textarea while still saving through the additional field.
* Classic and Block checkout: shipping phone and cellphone use the same Brazilian phone mask as billing phone (landline hyphen until 10 digits; mobile hyphen at 11).

= 0.8.13 - 2026-08-23 =
* Block checkout (Tab 1): drag fields within a section to set order. The plugin writes the existing `priority` values (copied to `index` on the storefront). Classic Checkout still uses the numeric Priority field.
* Block checkout: Shipping Address order also updates the matching native billing address fields (the Checkout Block shares one address form). Documents, contact, and order notes keep their own order. Row layout (left/right) is unchanged.

= 0.8.12 - 2026-08-21 =
* Block checkout: document fields (person type, gender, CPF/CNPJ masks, labels) render again when `company_as_name` is enabled. WooCommerce rejects `defaultFields` if core first/last name use JSON Schema objects, so those stay booleans; PJ still hides billing names in the browser and server validation still skips them.
* Block checkout: input masks keep the caret after the digits typed, so dots and dashes no longer jump the cursor or scramble the number.

= 0.8.11 - 2026-08-21 =
* Classic and Block checkout: with `company_as_name` enabled, billing first and last name stop being required when the customer selects PJ (fields are hidden) and become required again on PF. Shipping names are unchanged.

= 0.8.10 - 2026-08-21 =
* Classic checkout: changing house number (`billing_number` / `shipping_number`) no longer triggers `update_checkout` / shipping recalculation (same skip as complement).

= 0.8.9 - 2026-08-21 =
* Classic checkout: changing billing or shipping complement (`address_2`) no longer triggers `update_checkout` / shipping recalculation. Number, postcode, city, and state still refresh rates.

= 0.8.8 - 2026-08-21 =
* Classic and Block checkout: house number is no longer copied into WooCommerce `address_2`. Complement (`address_2`) and number stay independent; number remains in `billing_number` / `shipping_number` (and underscore meta).

= 0.8.7 - 2026-08-21 =
* Block checkout: Tab 1 **Block Checkout** row layout and priority now apply on the storefront. Address forms use flex wrap (WooCommerce only flexed inside a 700px container query); plugin number/neighborhood use native `address-form__` selectors.
* Block checkout: native address fields (country, postcode, names, etc.) follow **Shipping Address** Tab 1 settings for order and left/right columns (WooCommerce Blocks shares one AddressForm schema for shipping and billing). Classic checkout still uses the Classic `fields` map only.
* Block checkout: left-column fields start a new row (flex-break); an orphan right-column field is padded so it stays in the right column. Changing country/postcode priority and column no longer depends on a fixed country-then-postcode pair.

= 0.8.6 - 2026-08-19 =
* Classic checkout: Tab 1 row layout, required, and priority now survive WooCommerce `address-i18n.js` (BR locale inject + restore script after country/locale updates).
* Classic vs Block checkout: field settings no longer share one locale payload. Classic HTML uses `fields`; Checkout Block `countryData`/`defaultFields` use `block_fields`; Store API (`/wc/store/`) uses `block_fields` for address validation.
* Saving Tab 1 no longer copies Classic field values into Block settings when a block slug is missing from POST. First-load migration of empty `block_fields` is unchanged.

= 0.8.4 - 2026-07-05 =
* Checkout Fields (Tab 1): automatically opens the **Classic Checkout** or **Block Checkout** sub-tab based on how the store checkout page is built; contextual notice and **Active** badge indicate which checkout type is in use.

= 0.8.3 - 2026-06-21 =
* Checkout Fields (Tab 1): separate **Classic Checkout** and **Block Checkout** field settings (`fields` vs `block_fields`); existing stores migrate classic settings into block settings on first load.
* Block checkout: identity fields (CPF, CNPJ, person type, etc.) render in a **Documents** section at the top of the checkout form (before contact and address fields); number and neighborhood remain in both billing and shipping address forms.
* Block checkout backend: registrar, validator, row layout, and order notes use block-specific Tab 1 settings.

= 0.8.2 - 2026-06-16 =
* Classic checkout: Brazilian plugin fields, labels, row layout, masks, and validation are gated by selected country — when billing or shipping country is not Brazil, plugin-only fields are removed and WooCommerce defaults apply; selecting Brazil again restores admin-configured behavior.
* Block checkout: unchanged (country visibility already handled via JSON Schema).

= 0.8.1 - 2026-05-28 =
* CEP autofill (classic checkout): replaced inline searching/error text and row-break reflow with icon-only status inside the postcode field (loading spinner, brief success check, error marker) so checkout rows no longer shift across themes; CEP lookup errors show a lightweight bottom toast with auto-dismiss (configurable via `toastDismissMs` in checkout script config, default 5s).

= 0.8.0 - 2026-05-24 =
* Checkout Fields (Tab 1): replaced manual **CSS Class(es)** with **Row layout** radios — Full row, Left column, Right column — mapped to `form-row-wide` / `form-row-first` / `form-row-last` on classic checkout.
* Block checkout: row layout drives scoped flex CSS for WooCommerce and plugin fields; field **priority** maps to `index` for correct vertical order; placeholders and required/optional labels follow Tab 1 settings.
* Settings migration: existing saved `class` values are converted to `row_layout` automatically (legacy three-column classes map to left column).

= 0.7.4 - 2026-05-19 =
* Block checkout preflight: centralized admin notices for API availability, feature flag, kill-switch (`rbsmhao_disable_blocks_checkout_support`), and Brazilian Checkout Toolkit conflict detection; filter `rbsmhao_block_checkout_preflight_status` for tooling.
* Classic path guard: skip classic validation, persistence, ROAPC duplicate-document check, and classic checkout front assets when the Store API / Checkout Block handles the request.
* Readme: mandatory block checkout regression checklist (go/no-go) before production.

= 0.7.3 - 2026-05-19 =
* Read-only displays (My Account overview, order emails, admin order view): CPF, CNPJ, and phone/cellphone values are shown with Brazilian input masks even when stored as digits. REST API responses unchanged.

= 0.7.2 - 2026-05-19 =
* Read-only views (My Account address overview, order emails, order confirmation): hide **Person type** (`persontype`); CPF/CNPJ already indicate PF/PJ. Field remains on checkout and edit-address forms; REST API unchanged.

= 0.7.1 - 2026-05-19 =
* Block checkout: order notes field (`order_comments`) at order location; core order note block hidden when RaCar manages notes.
* Block checkout: mirror billing number/neighborhood to shipping meta when addresses match (Store API + classic processed order).
* Block checkout: read `_wc_billing/rbsmhao/*` meta in admin order display and WooCommerce REST enrichment.
* Block checkout: PF/PJ suppresses cross-person validation errors; order-location validation for required notes.

= 0.7.0 - 2026-05-19 =
* WooCommerce Checkout Block: registers Brazilian fields via `woocommerce_register_additional_checkout_field()` (WC 8.6+), with billing-only validation, PF/PJ visibility (JS), input masks, and dual-write to legacy `billing_*` / `_billing_*` meta for REST and integrations.
* New setting on Checkout Fields tab: enable or disable block checkout support (auto-disabled when Brazilian Checkout Toolkit is active to avoid duplicate fields).
* ROAPC: duplicate CPF/CNPJ check on Store API checkout when the customer opts to create an account (or when registration is required).

= 0.6.1 - 2026-05-16 =
* Order/customer persistence: read billing/shipping extras from WooCommerce’s sanitized checkout payload (same `billing_*` / `shipping_*` data used to build the order), so **new customers** and account-creation checkouts save CPF, number, neighborhood, etc. to **order meta** and **user meta** reliably for REST (Bling) consumption.
* User meta: invalid CPF/CNPJ values no longer block saving **all** other Brazilian fields — only the invalid document meta is omitted.
* Order/customer persistence: store `billing_persontype` as **1** / **2** (Brazilian Market contract); checkout UI still uses pf/pj via `default_checkout_billing_persontype`.
* When shipping to the billing address (no “Ship to a different address?”), mirror **billing** number/neighborhood into **shipping** meta (`shipping_number`, `_shipping_number`, `shipping_neighborhood`, `_shipping_neighborhood`) if shipping extras are empty—helps carriers and integrations that only read `_shipping_*`.
* Admin order edit: **Customer information** block shows each label and value on the same line (removed the `address` wrapper class so WooCommerce admin CSS no longer forces `strong` labels to `display: block`).
* New pt-BR translations.

= 0.6.0 - 2026-05-15 =
* WooCommerce REST API: exposes Brazilian checkout fields on orders and customers (`billing.cpf`, `billing.cnpj`, `billing.number`, `billing.neighborhood`, `persontype` as F/J, etc.) for Bling and similar integrations — no new public endpoints; uses existing WC REST permission checks.
* Order persistence: mirrors extra field meta as `_billing_*` / `_shipping_*` alongside existing keys for compatibility with legacy Brazilian Market data.

= 0.5.1 - 2026-05-15 =
* Checkout account field validation: fixed required checks for `account_username` and `account_password` to use WooCommerce account keys (instead of legacy `billing_*` prefixes), preventing false “required field” errors when those fields are filled on checkout.
* CEP autofill (classic checkout): while “searching” or “not found” feedback is shown, the next field row reflows as a full line below the postcode field (Storefront-like behavior) via a temporary row-break element — no changes to `form-row-first` / `form-row-last` / `form-row-wide` classes.
* CEP autofill: initial lookup on page load waits until checkout layout is ready (`updated_checkout` or `window` load) to avoid a brief broken layout flash.
* CEP autofill: manual address lookup runs as soon as 8 numeric digits are entered (`input` event); non-digits (e.g. hyphen from mask or manual typing) are ignored — lookup no longer waits for leaving the postcode field (blur).

= 0.5.0 - 2026-05-13 =
* Checkout Fields (Tab 1): optional Preserve two-column row layout on small screens (default **off**) for classic checkout — under `max-width: 768px`, scoped inline CSS restores `form-row-first` / `form-row-last` and three-column helper classes when themes stack fields full width; `form-row-wide` stays full width; `form-row-first` uses `clear: both` (with wide / three-col exclusions); checkout labels use `font-size: 70%` in that mode to reduce row misalignment; block checkout unaffected; FAQ entry added
* When plugin Select2 is disabled: SelectWoo/select2 removal is limited to checkout, My Account, and cart by default so third-party Select2 (theme filters, variations, etc.) keeps working site-wide
* Developer filter `rbsmhao_force_legacy_global_selectwoo_strip` (returns `bool`, receives settings array): return `true` to restore the previous site-wide strip behavior on stores that depended on it
* Checkout Fields (Tab 1) dimensions: when **select height** is set, inline CSS aligns **text-only** country rows (themes/filters that remove the country `select` and leave markup inside `#billing_country_field` / `#shipping_country_field` `.woocommerce-input-wrapper`) using scoped `display:flex`, `min-height`, and optional select line-height — **not** a global `span.woocommerce-input-wrapper` rule (avoids breaking other fields)
* Same dimension block: checkout `select.country_to_state` / `select.country_select` and My Account `select.country_to_state` get native height rules even when the theme drops `rbsmhao-select-field` on the country row
* Checkout frontend CSS: scoped `clear: both` on `.woocommerce-checkout .woocommerce-shipping-fields` so “Ship to a different address?” is not pulled beside floated billing rows (e.g. some Woodmart layouts)
* Birthdate: stored and validated as **d/m/Y** (Brazilian); legacy **Y-m-d** values in customer meta are normalized on checkout default; input mask treats ISO `Y-m-d` prefill before applying `dd/mm/aaaa`

= 0.4.1 - 2026-05-06 =
* Checkout Fields (Tab 1): added optional field dimension controls for classic checkout (separate height/line-height for all checkout selects and for text inputs); empty values inherit theme defaults
* Checkout frontend: unified select sizing model for native WooCommerce selects and Select2-rendered selects using the same checkout-scoped selectors/tokens (`.woocommerce-checkout`, `rbsmhao-select-field`) to reduce cross-theme mismatch
* Select2 frontend CSS: removed broad global overrides and reduced reliance on `!important`; styles are now scoped to checkout/plugin context to lower risk of theme conflicts
* Checkout layout compatibility: added optional **Classic Checkout Layout (Float Compatibility)** toggle (default off) with scoped `clear: both` behavior for `form-row-first` plus exclusions for wide rows and plugin three-column helper classes
* Documentation: expanded FAQ/troubleshooting with root-cause notes for float layouts (PF/PJ visibility changes, WooCommerce `country_to_state` row-class changes, and postcode class restore flow)
* Checkout locale integration: added support for WooCommerce `woocommerce_get_country_locale_base` and `woocommerce_get_country_locale_default` hooks (priority 20) in addition to `woocommerce_get_country_locale`
* Locale formatter internals: split callbacks by payload type (full locale map vs base/default locale fields) and introduced a shared merge helper to avoid duplicate logic
* Locale field classes: country field class enrichment is now idempotent (`update_totals_on_change` is appended only when missing), preventing duplicate classes in repeated locale passes
* My Account: billing/shipping **Edit address** (`woocommerce_billing_fields` / `woocommerce_shipping_fields`, priority 20) now includes Brazilian extras **Number** and **Neighborhood** when enabled in Checkout Fields settings (same visibility rules as checkout via `get_active_fields()`)
* My Account: Checkout Fields **dimension** settings (select/input height and line-height) and baseline plugin CSS now apply under `.woocommerce-account` as well as `.woocommerce-checkout` (registration, edit-address, etc.); **Classic Checkout Layout (Float Compatibility)** remains checkout-only

= 0.4.0 - 2026-05-04 =
* Checkout Fields (Tab 1): optional **Classic Checkout Layout (Float Compatibility)** toggle (default **off**) applies a scoped `clear: both` on `form-row-first` inside `.woocommerce-checkout form.checkout`, excluding `form-row-wide` and three-column helper classes; documented FAQ on PF/PJ visibility, `country_to_state`, and postcode row class restore
* Registration Form Fields (Tab 4): `rff` toggles for `account_username` and `account_password` follow WooCommerce Account & Privacy (manual username/password), are read-only in the admin UI with notice + link to WC settings, and are forced on sanitize; `updated_option` / `woocommerce_update_options_account` keep `rff` aligned when those WC options change
* Registration: user meta for optional account username/password from the extended registration form now uses WooCommerce keys `account_username` / `account_password` (not `billing_*`)
* Checkout Fields (Tab 1): WooCommerce-synced account username/password (`account_username`, `account_password`) — default settings and the checkout reset action now persist `enabled`/`required` from WooCommerce Account & Privacy (`woocommerce_registration_generate_username`, `woocommerce_registration_generate_password`); first-install activation uses the same default merge base instead of schema-only `enabled => false`
* When WooCommerce Account settings change, stored checkout field flags are reconciled if `enabled`/`required` for those account fields diverge (hooks: `woocommerce_update_options_account`, `updated_option` on the two registration options above)
* One Account Per CPF/CNPJ (Tab 3): “Use CPF or CNPJ as login username” (`cpf_login`) is available only when WooCommerce **Generate account login** is enabled; otherwise the toggle is off, read-only, with notice + link to **WooCommerce → Settings → Account & Privacy**, hidden input forces `cpf_login` off on save, and sanitization blocks forged POST values
* When WooCommerce disables generated account login (`woocommerce_registration_generate_username` → `no`), `cpf_login` is persisted off (`woocommerce_update_options_account`, `updated_option`); turning WC generation back on unlocks the toggle without auto-enabling the plugin option
* ROAPC: `cpf_as_username` and duplicate-login checks honour the same WooCommerce rule; CNPJ path now respects `cpf_login` instead of the non-existent `cnpj_login` key

= 0.3.5 - 2026-05-02 =
* Uninstall: records an informational entry in **WooCommerce → Status → Logs** (log source `racar-checkout-manager-uninstall`) with the user performing the uninstall (when available) and which plugin options were deleted; requires WooCommerce active and WC logging enabled per store settings
* Uninstall: fires the `rbsmhao_plugin_uninstalled` action so developers can persist an audit trail elsewhere (payload: `user_id`, `user_login`, `uninstalled_at`, `options_deleted`)

= 0.3.4 - 2026-05-01 =
* Checkout: added `RBSMHAO-checkout-frontend-style.css` (order notes / additional fields full-width when shipping row float layout breaks)
* Restored ViaCEP as a fallback CEP lookup when BrasilAPI fails or returns no valid address (same REST proxy `racar/v1/cep/{cep}`)
* Documented BrasilAPI + ViaCEP behaviour under External Services for WordPress.org transparency

= 0.3.2 - 2026-04-30 =
* Restructure of the RBSMHAO_Checkout_Fields class into smaller files, optmizing the load
    * Refactored checkout responsibilities into dedicated modules (schema, settings normalizer, sanitizer, validators, persistence, address formatter, and field filter)
* Standardized boolean operators in PHP codebase (`AND`/`OR` replaced by `&&`/`||`)
* Fixed One CPF/CNPJ registration validation flow that could allow duplicate CPF/CNPJ registration in some scenarios
* Fixed registration data persistence for first and last names on account creation flows
* Added `order_comments` management in Checkout Fields Tab with controls for enable/disable, label, placeholder, and required
* Improved first-activation migration to import existing WooCommerce field settings from billing, shipping, and order sections (including order notes)
* Registration Form Fields (Tab 4) now lists only billing fields, preventing shipping/order fields from appearing there
* Added safe key handling for ROAPC `rff` reads in Tab 4 to avoid PHP `Undefined array key` warnings on partial/legacy settings arrays
* Added synchronization between Checkout Tab (Tab 1) and ROAPC settings so `rff` follows `persontype`, CPF/CNPJ toggles, and `company_as_name`
* Added PF-only guard: when `persontype` is PF and Billing Company is disabled, `company_as_name` is automatically turned off and `rbsmhao_one_cpf_settings[rff][company]` is forced to `0` on save
* Added Tab 4 blocked-field behavior and contextual tooltips for:
    * `first_name`/`last_name` when PJ-only + Company as Name is enabled
    * `company` when PF-only + Billing Company is disabled
* Improved Tab 4 accessibility by associating text labels with their form controls via matching `for`/`id` attributes (fixes DevTools warning: “A `<label>` isn't associated with a form field”)
* Stopped loading unused Select2 admin stylesheet (`RBSMHAO-select2.css`); Select2 styling remains only on the storefront when the option is enabled
* Checkout frontend script (`RBSMHAO-checkout-fields-frontend-script.js`): when `#billing_persontype` is absent (e.g. PF-only/PJ-only checkout), initialization returns immediately so **no `MutationObserver` is attached** (this was the main performance fix; previously every DOM `childList` mutation still invoked the toggle path and spammed the console). When the field exists, `childList` updates are coalesced with `requestAnimationFrame`, and the old debug `console.log` was removed
* Fixed `wp_register_script` URL for the checkout frontend script to use the correct filename casing (`RBSMHAO-checkout-fields-frontend-script.js`) so the asset loads on case-sensitive hosts (separate from the observer/console issue above)
* Improved and standardized the save settings button in all tabs.
* Admin: sticky save bar on every settings tab (checkout fields, autofill, One CPF tabs) so the save row stays visible while scrolling long forms.
* Checkout: Brazilian extra shipping fields are validated only when “Ship to a different address?” is checked (and the cart needs a shipping address), aligned with WooCommerce so empty shipping extras do not block checkout when billing address is used for shipping.
* Checkout Fields (Tab 1): added WooCommerce account username and password as billing-managed fields (`account_username`, `account_password`), relocated from the account fieldset into the billing block for layout; visibility follows WooCommerce Account & Privacy settings (manual username/password); admin toggles for enable/required are locked with a link to WC settings; label, placeholder, priority, and CSS classes remain editable.
* Checkout: account username/password use server-side `required` when registration is mandatory (no guest checkout); when guest checkout is optional they stay optional until “Create an account?” is checked; companion script syncs visibility and required markers (asterisk / `validate-required`) so users are not shown “optional” for fields that must be filled.
* Checkout validation: registration-required orders rely on WooCommerce required-field checks for empty username/password; plugin avoids duplicate notices and keeps username format validation when relevant.

= 0.3.1 - 2026-04-26 =
* Removed ViaCEP because of lack of documentation/terms of use

= 0.3.0 - 2026-04-23 =
* Added option to save Company as Name
* Added option to register CPF/CNPJ as username One CPF tab
* Added registration form fields Manager
* Added option to make all fields wide on registration form
* Fixed several nonces throughout the plugin
* Removed function RBSMHAO_Checkout_Fields::render_user_profile_fields()
* Removed function RBSMHAO_Checkout_Fields::save_user_profile_fields()


* Tested on latest and greatest: PHP8.4, WP6.9, WC10.6

= 0.2.3 - 2026-04-19 =
* Fixed persontype field (was person_type)
* Fixed the validation logic based on admin settings
* Added funcionality: At activation, it gets data (priority, label, placeholder, required) from actual checkout fields in order to maintain compatibility
* Added the default WooCommerce fields to allow edition by user
* Fixed address display on orders
* Altered plugin slug from racar-brazilian-stores-must-have-add-on to racar-checkout-manager-for-brazilian-stores as per wp.org rules
* Updated translation to pt-BR.
* Tested on latest and greatest: PHP8.4, WP6.9, WC10.6

= 0.1.0 - 2026-03-15 =
* Initial release.
* Added CPF, CNPJ, RG, and other essential checkout fields.
* Integrated address autofill using CEP with BrasilAPI and ViaCEP.
* Added input masks for CPF, CNPJ, and cellphone fields.
* Fully compatible with WooCommerce HPOS.
* Translation-ready.

== Upgrade Notice ==

= 0.10.7 - 2026-09-07 =
* Block checkout: Complemento (address_2) stays visible for layout when enabled and optional in Tab 1, without making the field required.

= 0.10.6 - 2026-09-07 =
* company_as_name uses company as first name only; fixes shipping-phone meta warning on emails; Blocks integration boots only for Blocks checkout stores/requests.

= 0.10.5 - 2026-09-07 =
* Fixes duplicate username/password fields on My Account registration when the store lets customers set them manually.

= 0.10.4 - 2026-09-06 =
* Fixes a fatal parse error on PHP &lt; 8.0 when loading Blocks helpers; still requires PHP 8.0+ for the domain (and CLI).

= 0.10.3 - 2026-09-06 =
* ROAPC option rename: `all_fields_wide` → `registration_fields_wide` (auto-migrated); default on for new installs.

= 0.10.2 - 2026-09-05 =
* Tab 3: CPF/CNPJ as login username now requires and locks One Account Per CPF/CNPJ.

= 0.10.1 - 2026-09-03 =
* Block checkout layout fix: left/right field pairs stay on the same row in Tab 1 and on the storefront; swapping columns and drop slots behave correctly.

= 0.10.0 - 2026-09-02 =
* Performance and cleanup release: scoped input masks, deferred scripts, shared DocumentValidator for ROAPC, WooCommerce Blocks adapter, and Checkout autoload. Uninstall still preserves customer/order meta.

= 0.9.6 - 2026-08-27 =
* New Tab 1 option (on by default): apply Brazilian checkout fields and rules on the frontend for any country. Turn it off to restore the previous BR-only behavior.

= 0.9.5 - 2026-08-27 =
* Classic checkout: PF/PJ toggles now target billing field rows by ID (company, CPF/CNPJ, etc.) with the same company_as_name behavior as Block checkout — hide/show names, restore names when returning to PF, copy company into first/last on place order, and persist names on the order server-side.

= 0.9.4 - 2026-08-27 =
* Block checkout: Documents (identity) section renders first — before contact, shipping, and billing. Tab 1 Block field grid matches that section order.

= 0.9.3 - 2026-08-27 =
Single bootstrap on plugins_loaded; block vs classic checkout context follows the current page content (fixes latent thank-you/order-pay misdetection).

= 0.9.2 - 2026-08-27 =
WordPress.org conformity: requires WP 6.5+, WC tested up to 11.0; development prompt file removed from the plugin zip.

= 0.9.1 - 2026-08-27 =
Security hardening (no plaintext password meta; CEP REST cache/rate limit) and Block checkout CEP autofill/mask. Classic checkout autofill unchanged.

= 0.9.0 - 2026-08-24 =
Tab 1 visual field grid for Block and Classic. Block storefront fixes for contact password width, input height, and Documents spacing.

= 0.8.6 - 2026-08-19 =
Classic and Block checkout field settings are now isolated. Re-check Tab 1 Classic vs Block sub-tabs after update: row layout, required, and field order should match each sub-tab independently.

= 0.8.4 - 2026-07-05 =
Tab 1 now opens the Classic or Block checkout sub-tab automatically based on your store checkout page, with a notice showing which type is active.

= 0.8.3 - 2026-06-21 =
Tab 1 now has separate Classic and Block checkout field settings. Block checkout shows Brazilian identity fields in a Documents section at the top of the form.

= 0.8.2 - 2026-06-16 =
Classic checkout now hides Brazilian plugin fields when the selected billing or shipping country is not Brazil, and restores admin settings when Brazil is selected again.

= 0.6.1 - 2026-05-15 =
Checkout persistence saves Brazilian extras for new-account orders; person type stored as 1/2; shipping number/neighborhood mirror when billing is used for delivery.

= 0.4.2 - 2026-05-13 =
Safer SelectWoo default (scoped removal). Tab 1 select height and shipping fields clear fix. Optional legacy filter documented in the changelog.

= 0.1.0 =
Initial release of the plugin. Adds essential checkout fields and address autofill for Brazilian stores.

== License ==

This plugin is licensed under the GPLv2 or later. See the [GNU General Public License](https://www.gnu.org/licenses/gpl-2.0.html) for more details.