[ 'label' => ..., 'sections' => [ section => [ 'label' => ..., 'fields' => [ key => field ] ] ] ]. * * Field: type (toggle, text, textarea, code, color, number, select, image, lines), label, default, * description, options (select), min/max/step (number). * * @return array */ public static function fields(): array { $fields = array( 'general' => array( 'label' => __( 'General', 'aiolos-checkout-for-woocommerce' ), 'sections' => array( 'modules' => array( 'label' => __( 'Modules', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'checkout_enabled' => array( 'type' => 'toggle', 'label' => __( 'Checkout', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Replaces the checkout page with the Aiolos three-step checkout. The order-pay and thank-you pages stay WooCommerce\'s own.', 'aiolos-checkout-for-woocommerce' ), ), 'checkout_admins_only' => array( 'type' => 'toggle', 'label' => __( 'Test mode', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'Only logged-in shop managers see the new checkout; customers keep the old one until you switch this off.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_enabled' => array( 'type' => 'toggle', 'label' => __( 'Side cart', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'A cart that slides in from the side when a product is added or the cart icon is clicked.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'news' => array( 'label' => __( 'News from AiolosWeb', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'notices_enabled' => array( 'type' => 'toggle', 'label' => __( 'Show news and offers', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'Off until you turn it on. Then, once a day, the plugin asks aiolosweb.com for news about Aiolos Checkout (new features, offers), sending only the plugin version, the site language and the WordPress and WooCommerce versions — never your site\'s address or shop data. Shown on this settings screen only, one at a time, and each can be dismissed.', 'aiolos-checkout-for-woocommerce' ), ), ), ), ), ), 'design' => array( 'label' => __( 'Design', 'aiolos-checkout-for-woocommerce' ), 'sections' => array( 'brand' => array( 'label' => __( 'Brand', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'logo_id' => array( 'type' => 'image', 'label' => __( 'Logo', 'aiolos-checkout-for-woocommerce' ), 'default' => 0, 'description' => __( 'Shown in the checkout header. Without a logo the site\'s logo, or its name, is used.', 'aiolos-checkout-for-woocommerce' ), ), 'logo_height' => array( 'type' => 'number', 'label' => __( 'Logo height (px)', 'aiolos-checkout-for-woocommerce' ), 'default' => 36, 'min' => 16, 'max' => 120, ), 'logo_align' => array( 'type' => 'select', 'label' => __( 'Logo position', 'aiolos-checkout-for-woocommerce' ), 'default' => 'left', 'options' => array( 'left' => __( 'Left', 'aiolos-checkout-for-woocommerce' ), 'center' => __( 'Center', 'aiolos-checkout-for-woocommerce' ), ), ), 'logo_margin' => array( 'type' => 'number', 'label' => __( 'Space around the logo (px)', 'aiolos-checkout-for-woocommerce' ), 'default' => 0, 'min' => 0, 'max' => 40, 'description' => __( 'Extra space above and below the logo in the header.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'colors' => array( 'label' => __( 'Colors', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'color_primary' => array( 'type' => 'color', 'label' => __( 'Primary color', 'aiolos-checkout-for-woocommerce' ), 'default' => '#2b4bff', 'description' => __( 'Buttons, links, progress bars.', 'aiolos-checkout-for-woocommerce' ), ), 'color_button_text' => array( 'type' => 'color', 'label' => __( 'Button text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '#ffffff', 'description' => __( 'Text on buttons in the primary color.', 'aiolos-checkout-for-woocommerce' ), ), 'color_text' => array( 'type' => 'color', 'label' => __( 'Text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '#111827', ), 'color_muted' => array( 'type' => 'color', 'label' => __( 'Secondary text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '#6b7280', 'description' => __( 'Hints, notes and small print.', 'aiolos-checkout-for-woocommerce' ), ), 'color_success' => array( 'type' => 'color', 'label' => __( 'Savings color', 'aiolos-checkout-for-woocommerce' ), 'default' => '#15803d', 'description' => __( 'Discounts, free shipping, check marks.', 'aiolos-checkout-for-woocommerce' ), ), 'color_bg' => array( 'type' => 'color', 'label' => __( 'Page background', 'aiolos-checkout-for-woocommerce' ), 'default' => '#ffffff', ), 'color_header_bg' => array( 'type' => 'color', 'label' => __( 'Header background', 'aiolos-checkout-for-woocommerce' ), 'default' => '#ffffff', ), 'color_surface' => array( 'type' => 'color', 'label' => __( 'Order summary background', 'aiolos-checkout-for-woocommerce' ), 'default' => '#f4f5f7', 'description' => __( 'Also used for the side cart\'s footer and highlighted rows.', 'aiolos-checkout-for-woocommerce' ), ), 'color_field' => array( 'type' => 'color', 'label' => __( 'Field background', 'aiolos-checkout-for-woocommerce' ), 'default' => '#ffffff', ), 'color_border' => array( 'type' => 'color', 'label' => __( 'Field border color', 'aiolos-checkout-for-woocommerce' ), 'default' => '#d1d5db', ), // Empty defaults: follow the colors above until the shop picks its own; "Clear" goes back to that. 'color_button_hover' => array( 'type' => 'color', 'label' => __( 'Button hover color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Buttons in the primary color under the mouse. Empty: a darker shade of the primary color.', 'aiolos-checkout-for-woocommerce' ), ), 'color_secondary' => array( 'type' => 'color', 'label' => __( 'Secondary button color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Smaller buttons such as "Apply" for discount codes. Empty: the field background.', 'aiolos-checkout-for-woocommerce' ), ), 'color_qty_bubble' => array( 'type' => 'color', 'label' => __( 'Quantity bubble color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'The number on the product images of the summary. Empty: the secondary text color.', 'aiolos-checkout-for-woocommerce' ), ), 'color_summary_bg' => array( 'type' => 'color', 'label' => __( 'Summary box background', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Only the order summary box of the checkout. Empty: the order summary background above.', 'aiolos-checkout-for-woocommerce' ), ), 'color_summary_text' => array( 'type' => 'color', 'label' => __( 'Summary text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: readable on the summary background, chosen automatically.', 'aiolos-checkout-for-woocommerce' ), ), 'color_summary_link' => array( 'type' => 'color', 'label' => __( 'Summary link color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Links and "Remove" in the summary. Empty: the primary color.', 'aiolos-checkout-for-woocommerce' ), ), 'color_mobile_bar_bg' => array( 'type' => 'color', 'label' => __( 'Summary bar on phones', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'The "Show order summary" bar. Empty: the order summary background.', 'aiolos-checkout-for-woocommerce' ), ), 'color_bubble_text' => array( 'type' => 'color', 'label' => __( 'Quantity bubble text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: white or black, whichever reads better.', 'aiolos-checkout-for-woocommerce' ), ), 'color_button_hover_text' => array( 'type' => 'color', 'label' => __( 'Button text color under the mouse', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: the button text color.', 'aiolos-checkout-for-woocommerce' ), ), 'color_secondary_text' => array( 'type' => 'color', 'label' => __( 'Secondary button text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: readable on the secondary button, chosen automatically.', 'aiolos-checkout-for-woocommerce' ), ), 'color_secondary_hover' => array( 'type' => 'color', 'label' => __( 'Secondary button color under the mouse', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: a shade of the secondary button color.', 'aiolos-checkout-for-woocommerce' ), ), 'color_header_text' => array( 'type' => 'color', 'label' => __( 'Header text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: white or black, whichever reads better on the header background.', 'aiolos-checkout-for-woocommerce' ), ), 'color_footer_bg' => array( 'type' => 'color', 'label' => __( 'Footer background', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: the page background.', 'aiolos-checkout-for-woocommerce' ), ), 'color_footer_text' => array( 'type' => 'color', 'label' => __( 'Footer text color', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: the secondary text color.', 'aiolos-checkout-for-woocommerce' ), ), 'design_contrast' => array( 'type' => 'json', 'label' => __( 'Readability', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'render' => array( \AiolosCheckout\Checkout\Checkout::class, 'render_contrast' ), 'sanitize' => '__return_empty_string', ), ), ), 'shape' => array( 'label' => __( 'Shape and type', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'radius' => array( 'type' => 'number', 'label' => __( 'Corner radius (px)', 'aiolos-checkout-for-woocommerce' ), 'default' => 12, 'min' => 0, 'max' => 28, ), 'font' => array( 'type' => 'select', 'label' => __( 'Font', 'aiolos-checkout-for-woocommerce' ), 'default' => 'system', 'options' => array( 'system' => __( 'System font (fastest)', 'aiolos-checkout-for-woocommerce' ), 'theme' => __( 'Inherit from theme', 'aiolos-checkout-for-woocommerce' ), ), ), 'label_style' => array( 'type' => 'select', 'label' => __( 'Field labels', 'aiolos-checkout-for-woocommerce' ), 'default' => 'inset', 'options' => array( 'inset' => __( 'Inside the field', 'aiolos-checkout-for-woocommerce' ), 'above' => __( 'Above the field', 'aiolos-checkout-for-woocommerce' ), ), ), ), ), ), ), 'checkout' => array( 'label' => __( 'Checkout', 'aiolos-checkout-for-woocommerce' ), 'sections' => array( 'layout' => array( 'label' => __( 'Layout', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'checkout_layout' => array( 'type' => 'select', 'label' => __( 'Layout', 'aiolos-checkout-for-woocommerce' ), 'default' => 'steps', 'options' => array( 'steps' => __( 'Three steps (Details, Shipping, Payment)', 'aiolos-checkout-for-woocommerce' ), 'onepage' => __( 'One page (everything visible)', 'aiolos-checkout-for-woocommerce' ), ), 'description' => __( 'One page suits shops with few fields or digital products; steps keep long forms calm on phones.', 'aiolos-checkout-for-woocommerce' ), ), 'mobile_summary' => array( 'type' => 'select', 'label' => __( 'Order summary on phones', 'aiolos-checkout-for-woocommerce' ), 'default' => 'collapsed', 'options' => array( 'open' => __( 'Open', 'aiolos-checkout-for-woocommerce' ), 'collapsed' => __( 'Collapsed (tap to show)', 'aiolos-checkout-for-woocommerce' ), ), ), 'show_coupon' => array( 'type' => 'toggle', 'label' => __( 'Discount code field in the summary', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', ), 'hide_paid_shipping' => array( 'type' => 'toggle', 'label' => __( 'Hide paid shipping when shipping is free', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'Once a free shipping rate is offered, only the rates that cost nothing are shown (free shipping, free pickup).', 'aiolos-checkout-for-woocommerce' ), ), 'coupon_links' => array( 'type' => 'toggle', 'label' => __( 'Discount codes from links', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'A link to any page of your shop ending in ?coupon=CODE (for a newsletter, an ad or a post) applies the code; with an empty cart it waits for the first product.', 'aiolos-checkout-for-woocommerce' ), ), 'checkout_edit_cart' => array( 'type' => 'toggle', 'label' => __( 'Change quantities in the summary', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Plus, minus and remove buttons on the products of the order summary, so customers never go back to the cart.', 'aiolos-checkout-for-woocommerce' ), ), 'address_2_collapsed' => array( 'type' => 'toggle', 'label' => __( 'Hide "Apartment, suite" behind a link', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', ), 'hide_company' => array( 'type' => 'toggle', 'label' => __( 'Hide the company field', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', ), 'remove_theme_assets' => array( 'type' => 'toggle', 'label' => __( 'Distraction-free page', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Leaves the theme\'s styles and scripts off the checkout, for speed and a clean design. Plugins (payment gateways, analytics) keep theirs.', 'aiolos-checkout-for-woocommerce' ), ), 'header_text' => array( 'type' => 'text', 'label' => __( 'Header badge', 'aiolos-checkout-for-woocommerce' ), 'default' => __( 'Secure checkout', 'aiolos-checkout-for-woocommerce' ), ), 'below_button_text' => array( 'type' => 'text', 'label' => __( 'Text under the first button', 'aiolos-checkout-for-woocommerce' ), 'default' => __( 'You can review everything before you pay', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'options' => array( 'label' => __( 'Options', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'order_notes' => array( 'type' => 'select', 'label' => __( 'Order notes', 'aiolos-checkout-for-woocommerce' ), 'default' => 'collapsed', 'options' => array( 'show' => __( 'Show the field', 'aiolos-checkout-for-woocommerce' ), 'collapsed' => __( 'Behind an "Add a note" link', 'aiolos-checkout-for-woocommerce' ), 'hide' => __( 'Hide', 'aiolos-checkout-for-woocommerce' ), ), ), 'skip_cart_page' => array( 'type' => 'toggle', 'label' => __( 'Skip the cart page', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'Links to the cart go straight to the checkout while the cart has products; quantities can be changed in the order summary.', 'aiolos-checkout-for-woocommerce' ), ), 'sticky_summary' => array( 'type' => 'toggle', 'label' => __( 'Order summary follows the scroll', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'On computers the summary stays in view while the customer scrolls.', 'aiolos-checkout-for-woocommerce' ), ), 'summary_remove_button' => array( 'type' => 'toggle', 'label' => __( '"Remove" link on the products of the summary', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', ), 'summary_item_links' => array( 'type' => 'toggle', 'label' => __( 'Product names link to their pages', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', ), 'hide_billing_free_orders' => array( 'type' => 'toggle', 'label' => __( 'No billing address for free orders', 'aiolos-checkout-for-woocommerce' ), 'default' => 'no', 'description' => __( 'When there is nothing to pay, only the name, email and phone are asked for billing.', 'aiolos-checkout-for-woocommerce' ), ), 'highlighted_countries' => array( 'type' => 'json', 'label' => __( 'Countries at the top of the list', 'aiolos-checkout-for-woocommerce' ), 'default' => array(), 'render' => array( self::class, 'render_countries' ), 'sanitize' => array( self::class, 'sanitize_countries' ), 'description' => __( 'Shown first in the country dropdowns, in this order (for example Greece and Cyprus).', 'aiolos-checkout-for-woocommerce' ), ), 'mobile_coupon' => array( 'type' => 'toggle', 'label' => __( 'Discount code field on phones', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'On phones the order summary is folded: a discount code field is also shown above the payment methods.', 'aiolos-checkout-for-woocommerce' ), ), 'mobile_summary_label' => array( 'type' => 'text', 'label' => __( 'Summary bar text on phones', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'description' => __( 'Empty: "Show order summary".', 'aiolos-checkout-for-woocommerce' ), ), 'skip_single_shipping_step' => array( 'type' => 'toggle', 'label' => __( 'Skip the shipping step when there is one choice', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'With a single shipping rate and nothing to fill in under it, customers go from their details straight to payment; the method is shown in the review.', 'aiolos-checkout-for-woocommerce' ), ), 'auto_free_shipping' => array( 'type' => 'toggle', 'label' => __( 'Choose free shipping when it becomes available', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'When a discount code or a bigger order unlocks free shipping, it is selected for the customer, unless they picked a shipping method themselves.', 'aiolos-checkout-for-woocommerce' ), ), 'field_persistence' => array( 'type' => 'toggle', 'label' => __( 'Keep what customers typed', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Names, phone, email, notes and other fields are kept in the browser tab, so a reload or a trip back from another page does not empty the form. Card details and passwords are never kept; everything is cleared once the order is placed.', 'aiolos-checkout-for-woocommerce' ), ), 'postcode_validation' => array( 'type' => 'toggle', 'label' => __( 'Check postcodes before the next step', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'A postcode that does not fit the country is pointed out right away, with WooCommerce\'s own rules.', 'aiolos-checkout-for-woocommerce' ), ), 'phone_validation' => array( 'type' => 'toggle', 'label' => __( 'Check phone numbers', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Greek numbers need 10 digits (starting with 2 or 69), Cypriot 8; for other countries a number that looks too short or too long gets a hint only.', 'aiolos-checkout-for-woocommerce' ), ), 'rewards_at_checkout' => array( 'type' => 'toggle', 'label' => __( 'Free shipping and rewards bar in the summary', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'The same progress bar as in the side cart, at the top of the order summary.', 'aiolos-checkout-for-woocommerce' ), ), 'summary_show_savings' => array( 'type' => 'toggle', 'label' => __( 'Show savings in the summary', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Regular prices struck through on products on sale, and a "You save" line under the total.', 'aiolos-checkout-for-woocommerce' ), ), 'order_pay_styled' => array( 'type' => 'toggle', 'label' => __( 'Same design on the "Pay for order" page', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'The page customers reach to pay again after a failed payment, or from a payment link, gets the checkout\'s header and design. WooCommerce\'s own form stays, so every payment method works as before.', 'aiolos-checkout-for-woocommerce' ), ), 'split_address' => array( 'type' => 'select', 'label' => __( 'House number in its own field', 'aiolos-checkout-for-woocommerce' ), 'default' => 'auto', 'options' => array( 'auto' => __( 'Where the number follows the street (Germany, the Netherlands, Greece…)', 'aiolos-checkout-for-woocommerce' ), 'always' => __( 'For every country', 'aiolos-checkout-for-woocommerce' ), 'off' => __( 'Never (street and number in one field)', 'aiolos-checkout-for-woocommerce' ), ), 'description' => __( 'Couriers need the house number: a field of its own makes sure it is there. It is joined to the street in the country\'s usual order when the order is placed, and also kept on the order.', 'aiolos-checkout-for-woocommerce' ), ), 'optional_behind_links' => array( 'type' => 'toggle', 'label' => __( 'Optional company and phone behind a link', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'When optional, they are shown as "+ Company" and "+ Phone" links, for a shorter form.', 'aiolos-checkout-for-woocommerce' ), ), 'wc_company_field' => array( 'type' => 'json', 'label' => __( 'Company field (WooCommerce setting)', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'option' => 'woocommerce_checkout_company_field', 'render' => array( self::class, 'render_wc_field_option' ), 'sanitize' => array( self::class, 'sanitize_wc_company_field' ), ), 'wc_address_2_field' => array( 'type' => 'json', 'label' => __( 'Apartment, suite field (WooCommerce setting)', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'option' => 'woocommerce_checkout_address_2_field', 'render' => array( self::class, 'render_wc_field_option' ), 'sanitize' => array( self::class, 'sanitize_wc_address_2_field' ), ), 'wc_phone_field' => array( 'type' => 'json', 'label' => __( 'Phone field (WooCommerce setting)', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'option' => 'woocommerce_checkout_phone_field', 'render' => array( self::class, 'render_wc_field_option' ), 'sanitize' => array( self::class, 'sanitize_wc_phone_field' ), 'description' => __( 'Couriers and some payment methods (Klarna, PayPal Pay Later, cash on delivery services) need a phone number: keep it at least optional.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'scripts' => array( 'label' => __( 'Scripts', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'scripts_head' => array( 'type' => 'json', 'label' => __( 'Code in the page head', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'render' => array( self::class, 'render_scripts' ), 'sanitize' => array( self::class, 'sanitize_scripts_head' ), 'description' => __( 'Analytics or pixel code for the checkout and thank-you pages (the theme\'s own head code is left off these pages). Printed as written; only administrators who may post unfiltered HTML can change it.', 'aiolos-checkout-for-woocommerce' ), ), 'scripts_footer' => array( 'type' => 'json', 'label' => __( 'Code before the end of the page', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'render' => array( self::class, 'render_scripts' ), 'sanitize' => array( self::class, 'sanitize_scripts_footer' ), 'description' => __( 'Printed at the end of the checkout and thank-you pages.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'policies' => array( 'label' => __( 'Policies and footer', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'store_policies' => array( 'type' => 'json', 'label' => __( 'Store policies', 'aiolos-checkout-for-woocommerce' ), 'default' => array(), 'render' => array( self::class, 'render_policies' ), 'sanitize' => array( self::class, 'sanitize_policies' ), 'description' => __( 'Shown in the checkout footer and opened in a window over the checkout, so customers never leave it. The terms, privacy and refund pages set in WooCommerce and WordPress are listed already.', 'aiolos-checkout-for-woocommerce' ), ), 'footer_text' => array( 'type' => 'json', 'label' => __( 'Footer text', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'render' => array( self::class, 'render_html_text' ), 'sanitize' => array( self::class, 'sanitize_html_text' ), 'description' => __( 'Company details, a phone number for help… Links and bold text are allowed. Empty: the copyright line.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'contact' => array( 'label' => __( 'Contact details', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'email_suggestions' => array( 'type' => 'toggle', 'label' => __( 'Suggest fixes for mistyped emails', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( '"gmial.com" → "Did you mean gmail.com?", so order confirmations reach the customer. Checked in the browser; nothing is sent anywhere.', 'aiolos-checkout-for-woocommerce' ), ), 'returning_customer' => array( 'type' => 'toggle', 'label' => __( 'Offer to log in to returning customers', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'When the email entered belongs to an account, a "Log in" link appears under it. Needs "Allow customers to log into an existing account during checkout" in WooCommerce > Settings > Accounts & Privacy. Each visitor can check a limited number of addresses per hour.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'thankyou' => array( 'label' => __( 'Thank-you page', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'thankyou_account' => array( 'type' => 'toggle', 'label' => __( 'Offer guests an account on the thank-you page', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Guests choose a password and their order becomes an account (email, name and addresses from the order, earlier guest orders included), and they are logged in. Shown only for a recent order whose email has no account yet.', 'aiolos-checkout-for-woocommerce' ), ), 'thankyou_enabled' => array( 'type' => 'toggle', 'label' => __( 'Redesigned thank-you page', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'A confirmation with the order\'s progress at the top of the order-received page. Payment instructions (bank transfer) and tracking scripts that hook into the page keep working.', 'aiolos-checkout-for-woocommerce' ), ), 'thankyou_statuses' => array( 'type' => 'json', 'label' => __( 'Redesigned page for orders that are', 'aiolos-checkout-for-woocommerce' ), 'default' => array( 'processing', 'completed', 'on-hold', 'pending' ), 'render' => array( self::class, 'render_statuses' ), 'sanitize' => array( self::class, 'sanitize_statuses' ), 'description' => __( 'Orders in other statuses get WooCommerce\'s own thank-you page.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'trust' => array( 'label' => __( 'Trust', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'trust_items' => array( 'type' => 'lines', 'label' => __( 'Reassurance under the summary', 'aiolos-checkout-for-woocommerce' ), 'default' => implode( "\n", array( __( 'Secure, encrypted payment', 'aiolos-checkout-for-woocommerce' ), __( 'Order confirmation by email', 'aiolos-checkout-for-woocommerce' ), __( 'Easy returns', 'aiolos-checkout-for-woocommerce' ), __( 'Friendly support', 'aiolos-checkout-for-woocommerce' ), ) ), 'description' => __( 'One per line, each with a check mark. Leave empty to hide.', 'aiolos-checkout-for-woocommerce' ), ), ), ), ), ), 'fields' => array( 'label' => __( 'Fields', 'aiolos-checkout-for-woocommerce' ), 'sections' => array( 'tracking' => array( 'label' => __( 'Analytics events', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'tracking_events' => array( 'type' => 'select', 'label' => __( 'Send checkout events', 'aiolos-checkout-for-woocommerce' ), 'default' => 'off', 'options' => array( 'off' => __( 'Off', 'aiolos-checkout-for-woocommerce' ), 'datalayer' => __( 'To the dataLayer (Google Tag Manager)', 'aiolos-checkout-for-woocommerce' ), 'direct' => __( 'To the dataLayer, Google Analytics (gtag) and the Meta Pixel', 'aiolos-checkout-for-woocommerce' ), ), 'description' => __( 'GA4\'s begin_checkout, add_shipping_info, add_payment_info and purchase (once per order), with the products, value and coupon. Meta gets InitiateCheckout, AddPaymentInfo and Purchase. Only for tags your site already loads; turn it off if another plugin already sends these events.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'fields' => array( 'label' => __( 'Checkout fields', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'field_rules' => array( 'type' => 'json', 'label' => __( 'Fields', 'aiolos-checkout-for-woocommerce' ), 'default' => array(), 'render' => array( \AiolosCheckout\Checkout\Fields::class, 'render' ), 'sanitize' => array( \AiolosCheckout\Checkout\Fields::class, 'sanitize' ), 'wide' => true, ), 'simple_fields' => array( 'type' => 'json', 'label' => __( 'Extra fields', 'aiolos-checkout-for-woocommerce' ), 'default' => array(), 'render' => array( \AiolosCheckout\Checkout\CustomFields::class, 'render' ), 'sanitize' => array( \AiolosCheckout\Checkout\CustomFields::class, 'sanitize' ), 'wide' => true, 'description' => __( 'Up to 10 fields of your own (a gift message, a delivery note, a "how did you hear about us"), saved on the order and shown in the order screen and emails.', 'aiolos-checkout-for-woocommerce' ), ), ), ), ), ), 'side_cart' => array( 'label' => __( 'Side cart', 'aiolos-checkout-for-woocommerce' ), 'sections' => array( 'behaviour' => array( 'label' => __( 'Behaviour', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'side_cart_open_on_add' => array( 'type' => 'toggle', 'label' => __( 'Open when a product is added', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', ), 'side_cart_ajax_single' => array( 'type' => 'toggle', 'label' => __( 'Add to cart without reloading on product pages', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', 'description' => __( 'Simple, variable and grouped products; product add-on fields are sent along.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_button' => array( 'type' => 'select', 'label' => __( 'Floating cart button', 'aiolos-checkout-for-woocommerce' ), 'default' => 'bottom-right', 'options' => array( 'none' => __( 'None (use the theme\'s cart icon)', 'aiolos-checkout-for-woocommerce' ), 'bottom-right' => __( 'Bottom right', 'aiolos-checkout-for-woocommerce' ), 'bottom-left' => __( 'Bottom left', 'aiolos-checkout-for-woocommerce' ), ), ), 'side_cart_triggers' => array( 'type' => 'text', 'label' => __( 'Theme cart links that open it', 'aiolos-checkout-for-woocommerce' ), 'default' => 'a.cart-contents, .site-header-cart > li > a, a.footer-cart-contents, .wc-block-mini-cart__button, .header-cart-link, a.cart-customlocation, .elementor-menu-cart__toggle_button, .ast-site-header-cart .cart-container, .header-cart-button, .ct-cart-item, a.wcmenucart, .et-cart-info, .wd-header-cart > a, .fusion-main-menu-cart > a, .wc-menu-cart > a', 'description' => __( 'CSS selectors, separated by commas.', 'aiolos-checkout-for-woocommerce' ), ), 'side_cart_coupon' => array( 'type' => 'toggle', 'label' => __( 'Discount code field', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', ), 'side_cart_trust' => array( 'type' => 'lines', 'label' => __( 'Reassurance under the buttons', 'aiolos-checkout-for-woocommerce' ), 'default' => implode( "\n", array( __( 'Secure payment', 'aiolos-checkout-for-woocommerce' ), __( 'Easy returns', 'aiolos-checkout-for-woocommerce' ), __( 'Friendly support', 'aiolos-checkout-for-woocommerce' ), ) ), ), 'side_cart_low_stock' => array( 'type' => 'number', 'label' => __( '"Only N left" from', 'aiolos-checkout-for-woocommerce' ), 'default' => 5, 'min' => 0, 'max' => 100, 'description' => __( 'Shown for products that track stock with this many or fewer left. 0 hides it.', 'aiolos-checkout-for-woocommerce' ), ), ), ), 'shipping_bar' => array( 'label' => __( 'Free shipping bar', 'aiolos-checkout-for-woocommerce' ), 'fields' => array( 'free_shipping_bar' => array( 'type' => 'toggle', 'label' => __( 'Show the free shipping bar', 'aiolos-checkout-for-woocommerce' ), 'default' => 'yes', ), 'free_shipping_threshold' => array( 'type' => 'number', 'label' => __( 'Threshold', 'aiolos-checkout-for-woocommerce' ), 'default' => '', 'min' => 0, 'step' => '0.01', 'description' => __( 'Leave empty to read it from the "Free shipping" method of the customer\'s shipping zone. The bar only shows progress: the free shipping itself comes from your shipping methods.', 'aiolos-checkout-for-woocommerce' ), ), ), ), ), ), ); /** * Filters the settings schema (the Pro add-on adds its tabs here). * * @since 1.0.0 * * @param array $fields Tabs => sections => fields. */ return (array) apply_filters( 'aiolos_settings_fields', $fields ); } /** * Every field, flattened: key => field. * * @return array */ public static function flat_fields(): array { $flat = array(); foreach ( self::fields() as $tab ) { foreach ( (array) ( $tab['sections'] ?? array() ) as $section ) { foreach ( (array) ( $section['fields'] ?? array() ) as $key => $field ) { $flat[ $key ] = $field; } } } return $flat; } /** * All values, merged with defaults. * * @return array */ public static function all(): array { static $building = false; // A part that adds its fields after the first read (Pro, the side cart's options) must still // get its defaults: the cache is rebuilt when the fields filter has gained callbacks. $hook = $GLOBALS['wp_filter']['aiolos_settings_fields'] ?? null; $signature = $hook instanceof \WP_Hook ? (string) array_sum( array_map( 'count', $hook->callbacks ) ) : '0'; if ( null !== self::$values && ! $building && $signature !== self::$signature ) { self::$values = null; } if ( null === self::$values ) { $stored = get_option( self::OPTION, array() ); $stored = is_array( $stored ) ? $stored : array(); // A settings_fields filter that reads a setting gets the stored values instead of looping. if ( $building ) { return $stored; } $building = true; $defaults = array(); foreach ( self::flat_fields() as $key => $field ) { $defaults[ $key ] = $field['default'] ?? ''; } // A damaged value of the wrong kind (a list where text belongs) falls back to its default. foreach ( $defaults as $key => $default ) { if ( isset( $stored[ $key ] ) && is_scalar( $default ) && ! is_scalar( $stored[ $key ] ) ) { unset( $stored[ $key ] ); } } self::$values = array_merge( $defaults, $stored ); self::$signature = $signature; $building = false; } return self::$values; } /** * One value. * * @param string $key Key. * @param mixed $fallback Value when the key is unknown. * @return mixed */ public static function get( string $key, $fallback = '' ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : $fallback; } /** * Whether a toggle is on. * * @param string $key Key. */ public static function enabled( string $key ): bool { return 'yes' === self::get( $key, 'no' ); } /** * The non-empty lines of a "lines" setting. * * @param string $key Key. * @return string[] */ public static function lines( string $key ): array { $lines = preg_split( '/\r\n|\r|\n/', (string) self::get( $key ) ); return array_values( array_filter( array_map( 'trim', (array) $lines ), 'strlen' ) ); } /** * Sanitizes submitted values of one tab, keeping the other tabs' stored values. * * @param string $tab Tab key. * @param array $submitted Raw submitted values (unslashed). * @return array The full option value to store. */ public static function sanitize_tab( string $tab, array $submitted ): array { $schema = self::fields(); $stored = self::stored(); if ( empty( $schema[ $tab ]['sections'] ) ) { return $stored; } foreach ( $schema[ $tab ]['sections'] as $section ) { foreach ( (array) ( $section['fields'] ?? array() ) as $key => $field ) { if ( 'secret' === ( $field['type'] ?? '' ) ) { // Passwords and keys: an empty box keeps the saved value; "Remove" clears it. $new = is_string( $submitted[ $key ] ?? null ) ? trim( sanitize_text_field( $submitted[ $key ] ) ) : ''; if ( '' !== $new ) { $stored[ $key ] = $new; } elseif ( 'yes' === ( $submitted[ $key . '__clear' ] ?? '' ) ) { unset( $stored[ $key ] ); } continue; } $value = self::sanitize_value( $field, $submitted[ $key ] ?? null ); // A text left as its default is not stored, so it keeps following the site's // language (a stored copy would freeze it in the language of the admin who saved). if ( in_array( $field['type'] ?? 'text', array( 'text', 'lines', 'textarea' ), true ) && is_string( $field['default'] ?? null ) && '' !== $field['default'] && self::normalize_text( $value ) === self::normalize_text( $field['default'] ) ) { unset( $stored[ $key ] ); continue; } $stored[ $key ] = $value; } } return $stored; } /** * The saved settings, read from the database itself. A tab is saved on top of them, so a stale * or broken copy in an object cache would turn every other tab back to its defaults. * * @return array */ public static function stored(): array { global $wpdb; $raw = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", self::OPTION ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- the cached copy is what is not trusted here. if ( null === $raw || '' === $raw ) { return array(); } $value = maybe_unserialize( $raw ); if ( ! is_array( $value ) ) { // Never save over settings that cannot be read: the shop would lose all of them. wp_die( esc_html__( 'The saved settings could not be read, so nothing was changed. Please try again; if this keeps happening, clear the object cache.', 'aiolos-checkout-for-woocommerce' ), '', array( 'back_link' => true ) ); } // update_option() compares with the cached copy and skips the write when they match: drop it. wp_cache_delete( self::OPTION, 'options' ); wp_cache_delete( 'alloptions', 'options' ); return $value; } /** * A text compared without differences in line endings and surrounding spaces. * * @param mixed $text Text. */ private static function normalize_text( $text ): string { return trim( str_replace( array( "\r\n", "\r" ), "\n", (string) $text ) ); } /** * Sanitizes one value by its field type. * * @param array $field Field. * @param mixed $value Raw value. * @return mixed */ public static function sanitize_value( array $field, $value ) { $type = $field['type'] ?? 'text'; $default = $field['default'] ?? ''; switch ( $type ) { case 'toggle': return 'yes' === $value ? 'yes' : 'no'; case 'color': $color = sanitize_hex_color( is_string( $value ) ? $value : '' ); return $color ? $color : $default; case 'number': if ( null === $value || '' === $value || ! is_numeric( $value ) ) { return '' === $default ? '' : $default; } $number = (float) $value; if ( isset( $field['min'] ) ) { $number = max( (float) $field['min'], $number ); } if ( isset( $field['max'] ) ) { $number = min( (float) $field['max'], $number ); } return ( isset( $field['step'] ) && '0.01' === (string) $field['step'] ) ? round( $number, 2 ) : (int) round( $number ); case 'select': $value = is_string( $value ) ? $value : ''; return array_key_exists( $value, (array) ( $field['options'] ?? array() ) ) ? $value : $default; case 'image': $id = absint( $value ); return ( $id && wp_attachment_is_image( $id ) ) ? $id : 0; case 'textarea': case 'lines': return sanitize_textarea_field( is_string( $value ) ? $value : '' ); case 'code': // CSS: no tags (so nothing can close the