/** * Checkout's field groups, arranged into the two tabs `CheckoutSection` * renders: how the page is put together (`CheckoutLayoutFields`) and how the * form itself behaves (`CheckoutFormFields`). * * Each tab is a stack of `FieldGroup` cards rather than one flat run of * controls — the same shape Cart and Product Catalog already use, and for the * same reason: there are more settings here than read as a single list, but no * cluster large enough to earn a `WP_Customize_Section` of its own. * * One group crosses the tab line on purpose. Field spacing and input style * used to sit on the Form tab as form settings, but what they actually change * is how the page *looks*, not what it collects or validates — so they join * form width under Layout's "Visual style", and the Form tab is left to the * fields themselves. * * The groups stay separately exported so a caller can still reach for one on * its own. */ import type { ReactNode } from 'react'; import { __ } from '@wordpress/i18n'; import { ToggleControl, TextControl } from '@wordpress/components'; import { PanelsTopLeft, ReceiptText, ListOrdered, Brush, BadgeCheck, FileText, Globe, ShieldCheck, ShoppingCart, Settings2, } from 'lucide-react'; import SelectField from '../../../controls/select-field'; import CheckoutPreviewCards from '../../../controls/checkout-preview-cards'; import FieldGroup from '../../../controls/field-group'; import InfoNote from '../../../controls/info-note'; import type { WorkingSettings, SetPath, SectionExtra } from '../../../types'; import type { WooSchema } from '../types'; import { toOptions, ExtrasFields } from '../shared'; interface BaseProps { schema: WooSchema; working: WorkingSettings; setPath: SetPath; } const checkoutOf = ( working: WorkingSettings ) => ( ( ( working?.woocommerce ?? {} ) as Record< string, any > ).checkout ?? {} ) as Record< string, any >; // Unlike Cart's own `usingBlockCart`, this doesn't grey out the whole tab — // most Checkout options do reach the block checkout (see the theme's own // `woocommerce.scss`/`Cart_Checkout.php` for each one). Only the handful // below it that structurally can't are gated on it. export const usingBlockCheckout = ( schema: WooSchema ) => true === schema.using_block_checkout; // The counterpart to Cart's `BlockCartNotice`, rendered once above the tabs — // the greyed-out controls sit in both of them (Layout's editable/summary-panel // pair, Form's country flags and phone prefix), so one note at the top of the // view covers every one. Same shape and same reason as Cart's: an `InfoNote` // rather than a `Notice` because the one thing that matters is the button out // of it, and that button is a server-declared `action` field owned by the // companion plugin (see `Classic_Checkout_Panel_Section`, which targets // `woocommerce_checkout` exactly so it lands here) — hence the `footer` slot. // // The copy differs from Cart's on purpose: the block checkout leaves most of // this view working, so it says "a few options" rather than "some options". export function BlockCheckoutNotice( { schema, extras, }: { schema: WooSchema; extras?: SectionExtra[]; } ) { if ( ! usingBlockCheckout( schema ) ) { return null; } return (
} > { __( 'A few options are disabled because this store uses a new block-based checkout design.', 'aureon' ) }
); } /* ------------------------------------------------------------------------- * Layout tab * ---------------------------------------------------------------------- */ /** * Page layout — the one structural choice the rest of the tab hangs off: * whether the order summary gets a column beside the form, or the whole page * runs as a single stack. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function PageLayoutFields( { schema, working, setPath }: BaseProps ) { const checkout = checkoutOf( working ); return (
setPath( 'woocommerce.checkout.layout', value ) } />
); } /** * Order summary — where the review panel sits and how it behaves as the page * scrolls or narrows. * * The side and the panel treatment are both properties of the two-column * split, so a one-column checkout hides them rather than greying them out: * there is no column for them to describe. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function OrderSummaryFields( { schema, working, setPath }: BaseProps ) { const checkout = checkoutOf( working ); const blockCheckout = usingBlockCheckout( schema ); const twoColumn = 'one-column' !== checkout.layout; return (
{ twoColumn && ( setPath( 'woocommerce.checkout.summary_side', value ) } /> ) } setPath( 'woocommerce.checkout.sticky_summary', checked ) } /> setPath( 'woocommerce.checkout.mobile_summary', checked ) } /> setPath( 'woocommerce.checkout.editable_items', checked ) } /> { twoColumn && ( setPath( 'woocommerce.checkout.summary_panel', checked ) } /> ) }
); } /** * The step strip's look. Whether it shows at all is the group's own head * toggle (see `CheckoutLayoutFields`), so this is only ever rendered with the * strip already on — which is why there's no "hidden" option here: turning it * off is the switch above, and a card that did the same thing would be a * second control for one setting. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function StepIndicatorFields( { schema, working, setPath }: BaseProps ) { const checkout = checkoutOf( working ); return (
setPath( 'woocommerce.checkout.steps_style', value ) } />
); } /** * Visual style — the three measures that set the form's proportions. See the * file docblock for why spacing and input style live on this tab rather than * the Form one. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function VisualStyleFields( { schema, working, setPath }: BaseProps ) { const checkout = checkoutOf( working ); return (
setPath( 'woocommerce.checkout.form_width', value ) } /> setPath( 'woocommerce.checkout.density', value ) } /> setPath( 'woocommerce.checkout.input_style', value ) } />
); } /** * Additional elements — the optional content around the place-order button. * * @param root0 * @param root0.working * @param root0.setPath */ export function AdditionalElementFields( { working, setPath, }: Omit< BaseProps, 'schema' > ) { const checkout = checkoutOf( working ); return (
setPath( 'woocommerce.checkout.trust_badge', checked ) } /> { !! checkout.trust_badge && ( setPath( 'woocommerce.checkout.trust_text', value ) } /> ) } setPath( 'woocommerce.checkout.payment_icons', checked ) } /> setPath( 'woocommerce.checkout.place_order_text', value ) } />
); } /* ------------------------------------------------------------------------- * Form tab * ---------------------------------------------------------------------- */ /** * Location & format — the country-aware treatments on the address and phone * fields. Grouped together because all three key off the same thing: which * country the customer picked. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function LocationFields( { schema, working, setPath }: BaseProps ) { const checkout = checkoutOf( working ); const blockCheckout = usingBlockCheckout( schema ); return (
setPath( 'woocommerce.checkout.country_flags', checked ) } /> setPath( 'woocommerce.checkout.phone_country_code', checked ) } />
); } /** * Checkout extras — the two optional fields WooCommerce adds around the * address block, and how the coupon one is presented. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function ExtraFieldFields( { schema, working, setPath }: BaseProps ) { const checkout = checkoutOf( working ); const blockCheckout = usingBlockCheckout( schema ); return (
setPath( 'woocommerce.checkout.order_notes', checked ) } /> setPath( 'woocommerce.checkout.coupon', checked ) } /> { false !== checkout.coupon && ( setPath( 'woocommerce.checkout.coupon_style', value ) } /> ) }
); } /** * Advanced — the two whole-page treatments that don't belong to any one field. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function AdvancedFields( { schema, working, setPath }: BaseProps ) { const checkout = checkoutOf( working ); const blockCheckout = usingBlockCheckout( schema ); return (
setPath( 'woocommerce.checkout.labels_as_placeholders', checked ) } /> setPath( 'woocommerce.checkout.distraction_free', checked ) } />
); } /* ------------------------------------------------------------------------- * Tabs * ---------------------------------------------------------------------- */ /** * The Layout tab: how the checkout page is put together and proportioned. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function CheckoutLayoutFields( { schema, working, setPath, }: BaseProps ) { const checkout = checkoutOf( working ); return ( <> { /* The card's own head switch is the strip itself, so the style cards below only exist once it's on. */ } setPath( 'woocommerce.checkout.steps', checked ), label: __( 'Show a step indicator', 'aureon' ), } } > ); } /** * The Form tab: the fields the checkout collects and how they're presented. * * The first and third groups are WooCommerce core's own controls, physically * relocated into these cards from wherever core rendered them — see * `NativeFieldGroup` in `index.tsx` for how and why. They take `slots` rather * than children because that relocation is DOM work, not React's: this file * only says which card each set of core controls belongs in. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath * @param root0.slots Host-supplied containers for core's own controls — one * for the "Form fields" card, one for "Policies". A card * whose slot is absent isn't rendered at all. */ export function CheckoutFormFields( { schema, working, setPath, slots, }: BaseProps & { slots?: { fields?: ReactNode; policy?: ReactNode }; } ) { return ( <> { slots?.fields && ( { slots.fields } ) } { slots?.policy && ( { slots.policy } ) } ); }