*/ 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 ); } }