/** * Cart's field groups, arranged into the two tabs `CartSection` renders: what * the cart *looks like* (`CartDesignFields`) and what it *does* when a * customer acts (`CartBehaviorFields`). * * Every group is still one small cluster of controls under a `FieldGroup` * heading — none is big enough to be a `WP_Customize_Section` of its own, the * same call `SHOP_TABS` makes for Product Catalog's "General" — but there are * now seven of them, which is more than reads as one screen. The split is the * one Shop and Checkout already make: two views of the same settings behind a * segmented toggle, not two places to navigate to. * * The groups stay separately exported so a caller can still reach for one on * its own. */ import { __, sprintf } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; import { ToggleControl, TextControl, TextareaControl, } from '@wordpress/components'; import { LayoutGrid, Truck, ShoppingCart, ShoppingBasket, Package, Zap, } from '../../../icons'; import SelectField from '../../../controls/select-field'; import CartStyleCards from '../../../controls/cart-style-cards'; import FieldGroup from '../../../controls/field-group'; import InfoNote from '../../../controls/info-note'; import { focusSection, isCustomizerHost } from '../../../customize-bridge'; 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 cartOf = ( working: WorkingSettings ) => ( ( ( working?.woocommerce ?? {} ) as Record< string, any > ).cart ?? {} ) as Record< string, any >; const miniOf = ( working: WorkingSettings ) => ( ( ( working?.woocommerce ?? {} ) as Record< string, any > ).mini_cart ?? {} ) as Record< string, any >; // The header Cart element's "On click" is the one switch for whether a // mini-cart panel exists: `link` goes to the cart page, anything else opens a // drawer, dialog or popover. Mirrors `Cart_Checkout::mini_cart_enabled()`. const PANEL_BEHAVIORS = [ 'drawer', 'dialog', 'popover' ]; const miniCartPanelOn = ( working: WorkingSettings ) => PANEL_BEHAVIORS.includes( ( ( working?.header as Record< string, any > )?.elements?.cart ?.behavior as string ) ?? 'link' ); // Absent (older cached schema, or WooCommerce not yet reporting) reads as // "not block" rather than "block" — the safer default, since a false // positive would grey out working controls for every store until the // schema catches up, while a false negative just leaves the notice unshown // for a moment. export const usingBlockCart = ( schema: WooSchema ) => true === schema.using_block_cart; // Rendered once, above the tabs — it warns about controls spread across Cart // Layout, Empty Cart and Quick Cart, and a single note at the top of the view // covers every one of them. // // An `InfoNote` rather than a `Notice`: at 320px core's notice is a wall of // amber the eye slides off, and the one thing that matters here is the button // out of it. So the copy is cut to the single sentence that explains the grey // controls, and the companion plugin's own switch button (an `action` field it // declares — see `Classic_Checkout_Panel_Section` — hence the `footer` slot // rather than `onAction`) sits right under it. export function BlockCartNotice( { schema, extras, }: { schema: WooSchema; extras?: SectionExtra[]; } ) { if ( ! usingBlockCart( schema ) ) { return null; } return (
} > { __( 'Some options are disabled because this store uses a new block-based cart design.', 'aureon' ) }
); } /* ------------------------------------------------------------------------- * Cart tab * ---------------------------------------------------------------------- */ export function LayoutFields( { schema, working, setPath }: BaseProps ) { const cart = cartOf( working ); const blockCart = usingBlockCart( schema ); return (
setPath( 'woocommerce.cart.style', value ) } /> { /* Two one-of-three choices with short labels, so they pair on a line rather than each taking a full row of their own. */ }
setPath( 'woocommerce.cart.summary_side', value ) } /> setPath( 'woocommerce.cart.image_size', value ) } />
); } /** * Free-shipping meter. The card's own head toggle is the meter itself, so * everything below only exists once it's on. * * The threshold is the store's own free-shipping minimum by default — one * number, read from the shipping zone, with nothing to keep in sync. "Custom * amount" replaces that figure for a store that advertises a rounder one; it * does not stand in for a missing method, since the card only appears at all * once the store has one (see the group's own gate in `CartDesignFields`). * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function FreeShippingFields( { schema, working, setPath }: BaseProps ) { const cart = cartOf( working ); const panelOn = miniCartPanelOn( working ); const custom = ( cart.free_shipping_min as string ) ?? ''; // Which mode the select shows. Seeded from the stored amount, then held in // state so "Custom amount" can be picked before an amount has been typed — // an empty amount *is* the stored "use the store's own" value. const [ mode, setMode ] = useState( '' !== custom ? 'custom' : 'store' ); const needsAmount = 'custom' === mode && ! ( '' !== custom && Number( custom ) > 0 ); const symbol = schema.currency_symbol ?? ''; return (
{ setMode( value ); if ( 'store' === value ) { setPath( 'woocommerce.cart.free_shipping_min', '' ); } } } /> { 'custom' === mode && ( setPath( 'woocommerce.cart.free_shipping_min', value ) } /> ) } { needsAmount && ( { __( 'Enter an amount above — until then the meter falls back to your store’s own free-shipping minimum.', 'aureon' ) } ) } setPath( 'woocommerce.cart.drawer_progress', checked ) } /> setPath( 'woocommerce.cart.free_shipping_text', value ) } /> setPath( 'woocommerce.cart.free_shipping_done', value ) } />
); } export function EmptyFields( { schema, working, setPath }: BaseProps ) { const cart = cartOf( working ); const blockCart = usingBlockCart( schema ); return (
setPath( 'woocommerce.cart.empty_heading', value ) } /> setPath( 'woocommerce.cart.empty_text', value ) } /> setPath( 'woocommerce.cart.empty_cta', value ) } />
); } /* ------------------------------------------------------------------------- * Behavior tab * ---------------------------------------------------------------------- */ /** * What the cart does the moment a customer acts — the three switches that * decide whether an action costs a page load. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function QuickCartFields( { schema, working, setPath }: BaseProps ) { const cart = cartOf( working ); const panelOn = miniCartPanelOn( working ); const blockCart = usingBlockCart( schema ); return (
setPath( 'woocommerce.cart.quantity_autoupdate', checked ) } /> setPath( 'woocommerce.cart.ajax_add', checked ) } /> setPath( 'woocommerce.cart.open_drawer', checked ) } />
); } /** * What the mini-cart panel carries. * * There's no on/off switch here: the header Cart element's "On click" decides * whether a panel exists (see `miniCartPanelOn`). When it links to the cart * page, these stay visible but disabled — a store owner will want to see * their state before switching the panel back on — with a note pointing at * the setting that does. * * @param root0 * @param root0.working * @param root0.setPath */ export function MiniCartFields( { working, setPath }: BaseProps ) { const cart = cartOf( working ); const mini = miniOf( working ); const enabled = miniCartPanelOn( working ); const inCustomizer = isCustomizerHost(); const toggle = ( key: string, label: string, fallback = true, help?: string ) => ( setPath( `woocommerce.mini_cart.${ key }`, checked ) } /> ); return (
{ ! enabled && ( focusSection( 'aureon_header' ) : undefined } > { __( 'Your header cart links to the cart page. To use these settings, set the Cart element’s “On click” to Drawer, Dialog or Popover in Header.', 'aureon' ) } ) } { toggle( 'thumbnails', __( 'Show item thumbnails', 'aureon' ) ) } { toggle( 'subtotal', __( 'Show subtotal', 'aureon' ) ) } { toggle( 'view_cart', __( 'Show “View cart” button', 'aureon' ) ) } { toggle( 'checkout', __( 'Show “Checkout” button', 'aureon' ) ) } { toggle( 'auto_close', __( 'Auto close after adding', 'aureon' ), false, cart.open_drawer === false ? __( 'Needs “Open mini-cart on add” above — there is no panel to close otherwise.', 'aureon' ) : __( 'Dismiss the panel a few seconds after it opens, unless the customer reaches for it.', 'aureon' ) ) }
); } /** * The rest of the cart page's optional furniture — what it offers a customer * who isn't ready to check out yet, plus the one layout behaviour (sticky * totals) that is a behaviour rather than a look. * * @param root0 * @param root0.working * @param root0.setPath */ export function ShoppingFields( { working, setPath }: BaseProps ) { const cart = cartOf( working ); return (
setPath( 'woocommerce.cart.cross_sells', checked ) } /> setPath( 'woocommerce.cart.continue_shopping', checked ) } /> setPath( 'woocommerce.cart.sticky_totals', checked ) } />
); } /* ------------------------------------------------------------------------- * Tabs * ---------------------------------------------------------------------- */ /** * The Cart tab: how the cart page is put together, and the two pieces of copy * that render on it. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function CartDesignFields( { schema, working, setPath }: BaseProps ) { const cart = cartOf( working ); const blockCart = usingBlockCart( schema ); const freeShippingReady = schema.free_shipping_ready !== false; return ( <> { /* The meter counts toward the store's own free-shipping minimum, so with no amount-gated free-shipping method on any zone there is nothing for it to count toward — the switch greys out and says so, rather than turning on a bar that can only ever render nothing. */ } setPath( 'woocommerce.cart.free_shipping_bar', checked ), label: __( 'Show a free shipping meter', 'aureon' ), } } notice={ freeShippingReady ? undefined : ( { __( 'No shipping method on any zone offers free shipping above a minimum order amount, so the meter has nothing to count toward. Add one under WooCommerce → Settings → Shipping to turn this on.', 'aureon' ) } ) } > ); } /** * The Behavior tab: what the cart and its drawer do as products are added and * quantities change. * * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath */ export function CartBehaviorFields( { schema, working, setPath }: BaseProps ) { return ( <> ); }