=== BRCampos – Brazilian Checkout Fields for WooCommerce ===
Contributors: rgcglobalnet
Tags: cpf, cnpj, brasil, checkout, woocommerce
Requires at least: 6.6
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

CPF, CNPJ (including the 2026 alphanumeric CNPJ), número and bairro for the WooCommerce classic and block checkout.

== Description ==

BRCampos adds the fields Brazilian stores need to the WooCommerce checkout, and works with **both the classic checkout and the new block checkout**.

* **CPF and CNPJ with real validation.** Check digits are verified. The **alphanumeric CNPJ** introduced by the Receita Federal on 31 July 2026 (IN RFB 2.229/2024) is supported alongside the numeric one.
* **Customer type.** Individuals (CPF), companies (CNPJ) or both, with the company name required for companies (optional).
* **Número and bairro** for billing and shipping addresses, plus an optional cell phone, birth date and gender.
* **Block checkout.** Uses the WooCommerce Additional Checkout Fields API. The fields only show, and are only required, when the country is Brazil. A single "CPF / CNPJ" field detects which document was typed.
* **Drop-in replacement for "Brazilian Market on WooCommerce".** BRCampos stores data under the same order meta keys (`_billing_persontype`, `_billing_cpf`, `_billing_cnpj`, `_billing_number`, `_billing_neighborhood`, `_billing_cellphone`, `_shipping_number`, `_shipping_neighborhood`). Payment and shipping plugins that read those keys keep working, and old orders keep their data. While the old plugin is active, BRCampos pauses itself and shows a notice.
* **CEP autofill** of street, neighborhood, city and state (optional, classic checkout).
* **Input masks** for CPF, CNPJ, CEP and phones (classic checkout), without jQuery.
* Shown in the order admin, order e-mails and the formatted Brazilian address.
* HPOS (custom order tables) compatible.

BRCampos Pro (optional, sold separately at https://rgcglobalnet.com/brcampos/) adds company autofill from the CNPJ, the Inscrição Estadual field, CPF on the registration form with a uniqueness check, a CSV export for NF-e tools and import of the old plugin's settings. Everything listed above is free and complete.

= How it works =

1. Activate BRCampos. In the block checkout a single "CPF / CNPJ" field appears under the e-mail, and "Número" and "Bairro" appear in the address, only when the country is Brazil.
2. In the classic checkout the customer picks individual or company and sees only the fields for that type, with masks while typing and the address filled from the CEP.
3. On "Place order" the check digits are verified on the server. The values are saved under the classic meta keys and shown in the order screen, e-mails and REST API.

= Free vs Pro =

| Feature | Free | Pro |
| --- | --- | --- |
| CPF, CNPJ (numeric + alphanumeric) with check digits | Yes | Yes |
| Block checkout and classic checkout | Yes | Yes |
| Número, bairro, cell phone, birth date, gender | Yes | Yes |
| Same meta keys as Brazilian Market (no migration) | Yes | Yes |
| CEP autofill (classic), input masks | Yes | Yes |
| Company autofill from the CNPJ (classic checkout) | – | Yes |
| Inscrição Estadual (IE) field | – | Yes |
| CPF on registration, one account per CPF | – | Yes |
| Order CSV for NF-e tools (Bling, Tiny…) | – | Yes |
| Import of the old plugin's settings | – | Yes |

= External services =

**ViaCEP** (`https://viacep.com.br/`), used for the optional CEP autofill, which is on by default and can be turned off in WooCommerce → Settings → Advanced → BRCampos.

* What is sent: only the 8-digit CEP typed by the customer. The request goes straight from the customer's browser to ViaCEP. Your server sends nothing.
* When: when a customer with a Brazilian address finishes typing a CEP on the classic checkout.
* Terms and privacy: ViaCEP is a free public service. Conditions of use are described on https://viacep.com.br/ (no separate privacy policy is published).

No other remote calls are made.

== Installation ==

1. Install and activate the plugin (WooCommerce is required).
2. If "Brazilian Market on WooCommerce" is active, deactivate it. Your data stays.
3. Optional: adjust WooCommerce → Settings → Advanced → BRCampos.

== Frequently Asked Questions ==

= Do my payment gateways still find the CPF? =

Yes. BRCampos uses the same meta keys as the old plugin. In the block checkout, values are copied to those keys as well.

= Does it accept the new alphanumeric CNPJ? =

Yes, for example `12.ABC.345/01DE-35`. The check digits are calculated with the official method (character value = ASCII code − 48).

= Can I sell to other countries? =

Yes. The Brazilian fields are only shown and validated when the billing (or shipping) country is Brazil.

= Do I need to migrate my old orders? =

No. Old orders already store `_billing_cpf`, `_billing_number` and the other keys, and BRCampos reads the same keys. Deactivate "Brazilian Market on WooCommerce", activate BRCampos and you are done.

= Does the CEP autofill work in the block checkout? =

Not yet. In the block checkout WooCommerce controls the address fields, so the CEP autofill and masks are only on the classic checkout for now. CPF/CNPJ validation, número and bairro work in both.

= Does BRCampos issue NF-e? =

No. It collects and validates the data that NF-e tools need. Pro adds a CSV export for importing into your invoicing tool.

= Is the alphanumeric CNPJ accepted by my payment gateway? =

BRCampos accepts and validates it. Whether your gateway or ERP accepts letters in the CNPJ depends on that provider; ask them before you rely on it.

= Does it slow the checkout down? =

No. The script is a few kB without jQuery and only loads on the checkout and My Account pages. There are no custom tables.

== Screenshots ==

1. Block checkout: one "CPF / CNPJ" field, número and bairro, only for Brazilian addresses.
2. Invalid CPF stopped on "Place order" with a clear message.
3. Classic checkout for a company: CNPJ, razão social and IE (company autofill is Pro).
4. Order screen with the alphanumeric CNPJ 12.ABC.345/01DE-35 and cell phone.
5. Settings in WooCommerce › Settings › Advanced › BRCampos.
6. BRCampos Pro: licence, CSV export for NF-e tools and settings import.

== Changelog ==

= 1.0.0 =
* First release.

== Upgrade Notice ==

= 1.0.0 =
First release.
