From 535dbda6b48171f8115b455e54790de94d97d42a Mon Sep 17 00:00:00 2001 From: Murilo Ijanc Date: Sun, 26 Jul 2026 16:41:48 -0300 Subject: Initial import --- includes/class-cepis-woo-assets.php | 183 ++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 includes/class-cepis-woo-assets.php (limited to 'includes/class-cepis-woo-assets.php') diff --git a/includes/class-cepis-woo-assets.php b/includes/class-cepis-woo-assets.php new file mode 100644 index 0000000..def6fe2 --- /dev/null +++ b/includes/class-cepis-woo-assets.php @@ -0,0 +1,183 @@ + + */ + private static function config( string $checkout ): array { + return array( + 'baseUrl' => 'proxy' === Cepis_Woo_Options::mode() + ? Cepis_Woo_Rest::base_url() + : Cepis_Woo_Options::base_url(), + 'overwrite' => Cepis_Woo_Options::overwrite(), + 'focusNumero' => Cepis_Woo_Options::focus_number(), + 'debounceMs' => 250, + 'timeoutMs' => 8000, + 'messages' => Cepis_Woo_Messages::all(), + 'fields' => 'blocks' === $checkout ? self::blocks_fields() : self::classic_fields(), + ); + } + + /** + * CSS selectors for the classic checkout, per address section. + * + * `billing_number` and `billing_neighborhood` are not WooCommerce fields — + * they come from the "Brazilian Market on WooCommerce" plugin, which is the + * de-facto way a Brazilian store gets a house-number and a neighbourhood + * box. A selector that matches nothing is skipped, so listing them costs + * nothing on a store that does not have them. + * + * There is deliberately no fallback onto `address_2` for the neighbourhood: + * in WooCommerce that field means "apartment, suite, unit", and putting a + * neighbourhood there produces a wrong address on the shipping label. + * + * @return array> + */ + private static function classic_fields(): array { + $fields = array(); + + foreach ( array( 'billing', 'shipping' ) as $section ) { + $fields[ $section ] = array( + 'cep' => '#' . $section . '_postcode', + 'logradouro' => '#' . $section . '_address_1', + 'bairro' => '#' . $section . '_neighborhood', + 'localidade' => '#' . $section . '_city', + 'uf' => '#' . $section . '_state', + 'numero' => '#' . $section . '_number', + ); + } + + /** + * Filters the field selectors used on the classic checkout. + * + * Keys are the API's own field names; values are CSS selectors. A theme + * or one-page-checkout plugin that renames the fields hooks in here. + * + * @param array> $fields Selectors per address section. + */ + return (array) apply_filters( 'cepis_woocommerce_classic_fields', $fields ); + } + + /** + * Store API address keys for the Cart/Checkout Blocks. + * + * The block checkout has no house-number and no neighbourhood field, and no + * plugin currently adds one: "Brazilian Market on WooCommerce" only extends + * the classic form. A store that registers its own with + * `woocommerce_register_additional_checkout_field()` can map it here, using + * the namespaced key the Store API exposes it under. + * + * @return array + */ + private static function blocks_fields(): array { + $fields = array( + 'logradouro' => 'address_1', + 'localidade' => 'city', + 'uf' => 'state', + ); + + /** + * Filters the Store API address keys written on the block checkout. + * + * Keys are the API's own field names; values are keys of the address + * object in the `wc/store/cart` data store. + * + * @param array $fields Address keys per API field. + */ + return (array) apply_filters( 'cepis_woocommerce_blocks_fields', $fields ); + } +} -- cgit v1.3