# Cart and checkout Source: https://kart.bnomei.com/docs/content/cart-and-checkout Updated: 2025-08-08T14:02:38+00:00 Summary: Kirby Kart plugin docs: cart API methods, listing, adding/removing products, variants, stock management, checkout, tax, abandoned carts, JSON-LD schema. ## Available data - `$cart = kart()->cart();` - `$cart->add($product, $amount, $set, $variant)` - `$cart->allInStock()` - `$cart->canCheckout()` - `$cart->clear()` - `$cart->complete()` - `$cart->count()` - `$cart->delete()` - `$cart->fix()` - `$cart->formattedSubtotal()` - `$cart->has($product, $variant)` - `$cart->holdStock()` - `$cart->lines()` - `$cart->merge($user)` - `$cart->releaseStock($data)` - `$cart->remove($product, $amount, $variant)` - `$cart->save()` - `$cart->subtotal()` ## List products in cart Code (php): ``` cart()->lines() as $line) { /** @var \Bnomei\Kart\CartLine $line */ /** @var ProductPage $product */ $product = $line->product(); ?>
  • title() ?> hasStockForQuantity() === false) { ?> stock(withHold: true) ?> of quantity() ?>x quantity() ?>x formattedPrice() ?> formattedSubtotal() ?> */ ?>
  • ``` - `$line->decrement($amount)` - `$line->formattedPrice()` - `$line->formattedSubtotal()` - `$line->hasStockForQuantity()` - `$line->increment($amount)` - `$line->price()` - `$line->product()` - `$line->product()->stock(withHold:, variant:)` - `$line->product()->title()` - `$line->product()->url()` - `$line->quantity()` - `$line->subtotal()` ## Add product to cart Code (php): ``` inStock()) { ?>

    Out of stock

    remove() ?>"> ``` ## Buy now Code (php): ``` inStock()) { ?>

    out of stock

    stock() ?> or with stock in hold stock(withHold: true, variant: $variant) ?> ``` ## Product variants For all HTML forms (or API calls when using a headless setup) you can optionally forward a variant either combined or with each group. You can use `$product->variantGroups()` to help you build the HTML `select`-elements. Code (php): ```
    ``` ## Checkout Code (php): ```

    cart()->formattedSubtotal() ?> +tax

    ``` ## Merging of guest and customer carts When an anonymous user logs into their account, the cart and wishlist from their anonymous session will be merged with the data saved on their account. On logout, the cart and wishlist of the current session will be cleared. ## Tax The Kirby Kart plugin does not provide a preview of tax calculations because it does not have access to your customers' locations or shipping and billing addresses. However, once your customer proceeds to checkout and reaches the payment processing stage with your provider, they can enter this information and see the correct tax rate applied, or you roll out a custom solution. If your provider does not support automated tax calculation, you could query the customer for their shipping information at checkout, calculate taxes yourself, and forward the updated line items to the payment provider. ## Abandoned carts The Kirby Kart plugin does not retain a shopping cart beyond the current PHP session. It cannot send a notification to indicate that a cart has been abandoned after a certain period, such as 8 hours. However, once the checkout process is initiated, your provider will be aware of the checkout session that Kirby Kart started, allowing you to track it there. You may also use a customer ID to provide more insight. You can also use the [hooks](https://kart.bnomei.com/docs/guides/hooks) triggered by the Kart plugin to track events. ## JSON-LD Adding the following snippet to your dedicated checkout view will help search engines better understand the structure of your shop to output a [matching scheme](https://schema.org/CheckoutPage). Code (php): ``` ```