import type { Order } from '../../../types'; import { getSiteUrl } from '../../../shared/utils/urls'; /** The WooCommerce metadata sent with each booking item. */ export interface WooMetadata { wooShop: string; wooOrderId: string; /** The service the customer chose at checkout with Live courier rates; left out otherwise. */ wooCheckoutService?: string; } /** * WooCommerce metadata for a booking item. The single source for these keys. * * @param ref The booking's ref. * @param order The item's order, when known. * @return Metadata to add to the booking item. */ export function wooMetadata(ref: string, order?: Order | null): WooMetadata { const service = order?.shipping_method?.checkout?.serviceSlug; return { wooShop: getSiteUrl(), wooOrderId: ref, ...(service ? { wooCheckoutService: service } : {}), }; }