id = "addresszen"; $this->method_title = __( "AddressZen - Address Lookup", "addresszen" ); $this->method_description = __( "US and International Address Verification at checkout", "addresszen" ); // Load the settings $this->init_form_fields(); $this->init_settings(); $this->config = (object) [ "addresszen_enabled" => $this->get_option("addresszen_enabled"), "addresszen_api_key" => $this->get_option("addresszen_api_key"), "addresszen_populate_organisation" => $this->get_option( "addresszen_populate_organisation" ), "addresszen_populate_county" => $this->get_option( "addresszen_populate_county" ), "addresszen_watch_country" => $this->get_option( "addresszen_watch_country" ), "addresszen_separate_finder" => $this->get_option( "addresszen_separate_finder" ), "addresszen_autocomplete_override" => $this->get_option( "addresszen_autocomplete_override" ), "addresszen_address_finder_label" => $this->get_option( "addresszen_address_finder_label" ), "addresszen_address_line_3_field" => $this->get_option( "addresszen_address_line_3_field" ), ]; add_action("woocommerce_update_options_integration_" . $this->id, [ $this, "process_admin_options", ]); // Add action for admin settings page if (is_admin()) { add_action("admin_footer", [$this, "add_admin_settings_js"]); } if ($this->config->addresszen_enabled === "yes") { //AddressZen custom action - only load legacy script on non-blocks checkout add_action("wp_enqueue_scripts", [$this, "load_scripts"]); add_action("admin_enqueue_scripts", [$this, "load_admin_scripts"]); } } public function init_form_fields() { // Tab 1: Basic Settings $this->basic_fields = [ "addresszen_required" => [ "title" => __("Required", "addresszen"), "type" => "title", "description" => "", "id" => "addresszen_required", ], "addresszen_enabled" => [ "id" => "addresszen_enabled", "title" => __("Enabled", "addresszen"), "type" => "checkbox", "description" => __( "Globally activate or deactivate this plugin", "addresszen" ), "default" => "yes", ], "addresszen_api_key" => [ "id" => "addresszen_api_key", "title" => __("API Key", "addresszen"), "type" => "text", "description" => __( "Security Note: Before going into production, restrict your API key to requests from your domain URL only.", "addresszen" ), ], "addresszen_features" => [ "title" => __("Features", "addresszen"), "type" => "title", "description" => "", "id" => "addresszen_features", ], "addresszen_autocomplete" => [ "id" => "addresszen_autocomplete", "title" => __("Enable Address Lookup", "addresszen"), "type" => "checkbox", "description" => __( "Toggles customer facing Address Lookup functionality in checkout and accounts pages", "addresszen" ), "default" => "yes", ], "addresszen_admin_autocomplete" => [ "id" => "addresszen_admin_autocomplete", "title" => __("Enable Admin Address Lookup", "addresszen"), "type" => "checkbox", "description" => __( "Toggles Address Lookup functionality on your WooCommerce administrative pages like order creation and editing", "addresszen" ), "default" => "yes", ], ]; // Tab 2: Advanced Settings $this->advanced_fields = [ "addresszen_behaviour" => [ "title" => __("Behaviour", "addresszen"), "type" => "title", "description" => "", "id" => "addresszen_behaviour", ], "addresszen_watch_country" => [ "id" => "addresszen_watch_country", "title" => __( "Enable Address Validation based on country", "addresszen" ), "type" => "checkbox", "description" => __( "Enabling this feature will disable Address Lookup when an unsupported territory is selected", "addresszen" ), "default" => "false", ], "addresszen_separate_finder" => [ "id" => "addresszen_separate_finder", "title" => __( "Create a Separate Field for Address Lookup", "addresszen" ), "type" => "checkbox", "description" => __( "Enabling this feature will move the Address Lookup into a separate input field above the main address form", "addresszen" ), "default" => "false", ], "addresszen_separate_finder_position" => [ "id" => "addresszen_separate_finder_position", "title" => __( "Separate Lookup Position", "addresszen" ), "type" => "select", "description" => __( "Choose where to position the separate Address Lookup field", "addresszen" ), "default" => "above_address", "options" => [ "above_address" => __("Above Address Line 1", "addresszen"), "above_company" => __("Above Company Field", "addresszen"), ], ], "addresszen_address_finder_label" => [ "id" => "addresszen_address_finder_label", "title" => __("Address Finder Label", "addresszen"), "type" => "text", "description" => __( "Customise the label shown on the separate Address Finder input field. Leave blank for the default.", "addresszen" ), "default" => "", ], "addresszen_hide_address_fields" => [ "id" => "addresszen_hide_address_fields", "title" => __( "Hide Address Fields Until Selection", "addresszen" ), "type" => "checkbox", "description" => __( "When using the separate Address Lookup, this will hide the address fields until an address is selected.", "addresszen" ), "default" => "false", ], "addresszen_allow_manual_entry" => [ "id" => "addresszen_allow_manual_entry", "title" => __( "Allow Manual Address Entry", "addresszen" ), "type" => "checkbox", "description" => __( "Show a link to allow customers to enter their address manually instead of using Address Lookup", "addresszen" ), "default" => "yes", ], "addresszen_address_output" => [ "title" => __("Address Output", "addresszen"), "type" => "title", "description" => "", "id" => "addresszen_address_output", ], "addresszen_populate_organisation" => [ "id" => "addresszen_populate_organisation", "title" => __("Remove Organisation Name", "addresszen"), "type" => "checkbox", "description" => __( "Removes the Company name from the address lines to avoid duplicate with Company Name field", "addresszen" ), "default" => "yes", ], "addresszen_populate_county" => [ "id" => "addresszen_populate_county", "title" => __("Enable County/State", "addresszen"), "type" => "checkbox", "description" => __( "This will populate the county/state field from the address data.", "addresszen" ), "default" => "yes", ], "addresszen_address_line_3_field" => [ "id" => "addresszen_address_line_3_field", "title" => __("Third Address Line Field", "addresszen"), "type" => "text", "description" => __( "Block checkout only. ID of an additional address field registered with woocommerce_register_additional_checkout_field (e.g. my-plugin/address-3) to receive the third address line. Leave blank to append the third line to Address line 2.", "addresszen" ), "default" => "", ], "addresszen_overrides" => [ "title" => __("Configuration Overrides", "addresszen"), "type" => "title", "description" => __("These settings allow for highly customisable integrations. Invalid input will break your integration.", "addresszen"), "id" => "addresszen_overrides", ], "addresszen_autocomplete_override" => [ "id" => "addresszen_autocomplete_override", "title" => __( "Address Lookup Configuration Override", "addresszen" ), "type" => "textarea", "description" => __( "JSON configuration to override Address Lookup settings. Leave blank to disable.", "addresszen" ), "default" => "", ], ]; // Tab 3: Validation Settings $this->validation_fields = [ "addresszen_validation" => [ "title" => __("Address Format", "addresszen"), "type" => "title", "description" => __("Configure address format validation and transformations", "addresszen"), "id" => "addresszen_validation", ], "addresszen_limit_line_one" => [ "id" => "addresszen_limit_line_one", "title" => __("Limit Address Line One Length", "addresszen"), "type" => "checkbox", "description" => __( "Enable to enforce a maximum character limit on address line one", "addresszen" ), "default" => "no", ], "addresszen_max_line_one" => [ "id" => "addresszen_max_line_one", "title" => __("Maximum Address Line One Length", "addresszen"), "type" => "number", "description" => __( "Maximum number of characters allowed in address line one (default: 40)", "addresszen" ), "default" => "40", "custom_attributes" => [ "min" => "10", "max" => "255", ], ], "addresszen_transliterate" => [ "id" => "addresszen_transliterate", "title" => __("Transliterate Accented Characters", "addresszen"), "type" => "checkbox", "description" => __( "Convert accented and special characters to their ASCII equivalents (e.g., é → e, ñ → n)", "addresszen" ), "default" => "no", ], "addresszen_ascii_only" => [ "id" => "addresszen_ascii_only", "title" => __("ASCII Characters Only", "addresszen"), "type" => "checkbox", "description" => __( "Only allow ASCII characters and common accented characters. Special characters will be removed.", "addresszen" ), "default" => "no", ], "addresszen_us_zip5_only" => [ "id" => "addresszen_us_zip5_only", "title" => __("Use Standard US ZIP Codes", "addresszen"), "type" => "checkbox", "description" => __( "Use US ZIP codes in the traditional 5-digit format (90210) instead of the ZIP+4 format (90210-1234)", "addresszen" ), "default" => "yes", ], "addresszen_company" => [ "title" => __("Company Name Handling", "addresszen"), "type" => "title", "description" => __("Configure how company names are handled in addresses", "addresszen"), "id" => "addresszen_company", ], "addresszen_fill_company" => [ "id" => "addresszen_fill_company", "title" => __("Populate Company Name Field", "addresszen"), "type" => "checkbox", "description" => __( "Automatically populate the company name field from the address if present", "addresszen" ), "default" => "no", ], "addresszen_restrictions" => [ "title" => __("Address Restrictions", "addresszen"), "type" => "title", "description" => __("Block certain types of addresses", "addresszen"), "id" => "addresszen_restrictions", ], "addresszen_block_po_boxes" => [ "id" => "addresszen_block_po_boxes", "title" => __("Block PO Box Addresses", "addresszen"), "type" => "checkbox", "description" => __( "Prevent customers from using PO Box addresses", "addresszen" ), "default" => "no", ], ]; // Merge all fields for saving/processing (required by WC_Settings_API) $this->form_fields = array_merge($this->basic_fields, $this->advanced_fields, $this->validation_fields); } /** * Override admin_options to render tabbed interface */ public function admin_options() { ?>