true, 'city_required' => true, 'replace_city_field' => true, 'custom_cities' => [], ]; } /** * {@inheritDoc} */ public function settingsSchema(): array { return [ 'persian_state_labels' => [ 'type' => 'checkbox', 'label' => __( 'نام فارسی استان‌ها', 'rahkar-toolkit' ), 'help' => __( 'ووکامرس استان‌ها را به شکل «Tehran (تهران)» نمایش می‌دهد. با این گزینه فقط نام فارسی نشان داده می‌شود. کد استان تغییر نمی‌کند، پس سفارش‌های قبلی و افزونه‌های حمل‌ونقل دست‌نخورده می‌مانند.', 'rahkar-toolkit' ), 'default' => true, ], 'replace_city_field' => [ 'type' => 'checkbox', 'label' => __( 'تبدیل فیلد شهر به لیست انتخابی', 'rahkar-toolkit' ), 'help' => __( 'به‌جای فیلد متنی آزاد، لیست شهرهای استان انتخاب‌شده نمایش داده می‌شود.', 'rahkar-toolkit' ), 'default' => true, ], 'city_required' => [ 'type' => 'checkbox', 'label' => __( 'شهر اجباری باشد', 'rahkar-toolkit' ), 'default' => true, ], ]; } /** * {@inheritDoc} */ public function settingsSections(): array { return []; } /** * {@inheritDoc} */ public function register(): void { // Every callback below is a lazy closure. `CheckoutFields` is only // constructed once one of these hooks actually fires, so a product page — // which fires none of them — never opens the file. // `woocommerce_states` fires on ordinary pages too, so it deliberately // resolves the small ProvinceLabels class rather than CheckoutFields — // otherwise the address-field machinery would load store-wide. if ( $this->bootSwitch( 'persian_state_labels' ) ) { add_filter( 'woocommerce_states', static fn( array $states ): array => Plugin::make( ProvinceLabels::class )->filter( $states ) ); } if ( $this->bootSwitch( 'replace_city_field' ) ) { add_filter( 'woocommerce_default_address_fields', static fn( array $fields ): array => Plugin::make( CheckoutFields::class )->addressFields( $fields ) ); add_filter( 'woocommerce_checkout_fields', static fn( array $fields ): array => Plugin::make( CheckoutFields::class )->seedSavedCity( $fields ) ); // `wp_enqueue_scripts` fires on every front-end page, so the page test // happens in the closure — which lives in this already-loaded file — // rather than inside the handlers. Testing it there would load them // store-wide just to be told the page has no address form. // // The two checkouts are mutually exclusive: the block checkout has no // `