=== Brazilian Checkout Fields for WooCommerce ===
Contributors: catcodestudio
Tags: brazil, cpf, cnpj, cep, checkout fields
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
WC requires at least: 9.9
WC tested up to: 11.2
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

CPF, CNPJ (with the new alphanumeric CNPJ), number and neighborhood on the classic and the block checkout, with address from the CEP.

== Description ==

A shop in Brazil needs the buyer's CPF or CNPJ, the house number and the neighborhood, none of which WooCommerce asks for. This plugin adds them to the **classic checkout and the block checkout**, checks them on the server, and fills in the address from the CEP.

**Moving from Brazilian Market on WooCommerce?** Your orders and customers need no conversion. This plugin stores the data under the same keys (`_billing_cpf`, `_billing_cnpj`, `_billing_number`, `_billing_neighborhood` and the rest), so past orders show up filled in, and gateways, invoice tools and ERP connectors that read those keys keep working. The WooCommerce REST API returns the same fields in the same format. One click copies the settings, and the plugin waits until you switch the older one off, so the two never fight over the checkout.

Included:

* **Block checkout and classic checkout**, with HPOS. The block fields use WooCommerce's Additional Checkout Fields API, so they also appear in My Account and on the order screen, where you can edit them.
* **Alphanumeric CNPJ.** From July 2026 the Receita Federal issues CNPJ with letters, and the old numbers stay valid. Both formats are accepted and checked, by the official calculation.
* Person type: individuals (CPF), companies (CNPJ), both, or no document at all.
* Optional RG, state registration, date of birth, gender and a separate cell phone field.
* Number and neighborhood in the billing and the shipping address, and in every formatted address.
* **Address from the CEP** through ViaCEP, with BrasilAPI as the backup when ViaCEP is down. The shop's server asks, so the buyer's IP stays with the shop, and answers are cached.
* Masks while typing for CPF, CNPJ, CEP, phone and date of birth.
* Check digits verified on the server for CPF and CNPJ. A value is stored in one format however it was typed.
* Ask buyers from Brazil only, or everyone.
* Search the orders list by CPF or CNPJ.
* Personal-data export and erasure through the WordPress privacy tools.

Pro (licence from catcode.com.ua, with a 7-day trial):

* Translations: English and Brazilian Portuguese, in the package.
* **CNPJ lookup** at the checkout: the company name and the address are filled in from the public company register.
* **Company status**: a CNPJ that is closed, suspended or unfit gets a note on the order, or is refused if you choose so. A service that is down, or a CNPJ missing from its data, never stops an order.
* **One document per account**: warn about, or refuse, a CPF or CNPJ that already belongs to another customer account.
* **IBGE city code** stored with every order.
* **CSV export** of orders with the document, state registration, full address and IBGE code, for your invoicing system.
* **Data check**: a list of past orders with an invalid CPF or CNPJ, no document, no number or no CEP.
* New versions in Dashboard → Updates.

This plugin does not issue an NF-e and does not calculate shipping. It collects and checks the data those need.

== External services ==

Address and company lookups go from the shop's server and send nothing but the number being looked up. The buyer's IP address, name and the rest of the order are not sent.

**ViaCEP** (viacep.com.br): looks up the address for a CEP. The CEP is sent when a buyer types it at the checkout, unless you switch "Fill in the address from the CEP" off. Service site: https://viacep.com.br/

**BrasilAPI** (brasilapi.com.br): the same CEP lookup when ViaCEP cannot be reached. Service site and terms: https://brasilapi.com.br/ and https://github.com/BrasilAPI/BrasilAPI

**BrasilAPI**, Pro only: looks up a company by its CNPJ, which is public register data. The CNPJ is sent when a buyer types it at the checkout, unless you switch the lookup and the status check off.

**catcode.com.ua**, Pro only: activating a licence or starting the trial sends the key or e-mail address and the site address, and WordPress asks for new versions. Terms: https://catcode.com.ua/terms/

== Installation ==

1. Upload the plugin and activate it. WooCommerce 9.9 or newer must be active.
2. If Brazilian Market on WooCommerce is active, its settings are copied on activation. Check them under WooCommerce → Brazilian Fields, then deactivate the older plugin: until then this one waits.
3. Choose who buys from you and which optional fields to ask for.
4. Place a test order on the checkout you use.

== Frequently Asked Questions ==

= Do I have to convert old orders or customers? =
No. Both plugins use the same keys for orders and customers.

= What happens to the older plugin's settings? =
They are copied once, when this plugin is activated on a site that has them and no settings of its own yet. The settings page has a button to copy them again. The e-mail typo suggestion of the older plugin is not part of this plugin, and neither is its layout option: the fields follow the layout of your checkout.

= Does custom code written for the older plugin still work? =
The filters `wcbcf_billing_fields`, `wcbcf_shipping_fields` (classic checkout) and `wcbcf_disable_checkout_validation` are still applied. Code that calls the older plugin's PHP classes directly does not work, because they are gone.

= Is the state registration verified? =
Its format only: a number or ISENTO. The check digits differ per state and are not verified.

= Why does the block checkout ask "I am buying as a company" with a checkbox? =
The classic checkout shows two radio buttons. WooCommerce's block fields offer text, checkbox, select and date, and with two options a checkbox is one click.

= What does a buyer from abroad see? =
With "Ask buyers from Brazil only" on, which is the default, none of these fields. The classic checkout also keeps the company field for them.

= Does the plugin work with an older WooCommerce? =
No. It needs 9.9, the first version whose block fields can depend on the country and the person type. On an older version it shows a notice and adds nothing.

== Changelog ==

= 1.0.1 =
* Readme cleaned up.

= 1.0.0 =
* First release.
