Skip to main content

useCart

This hook is used to get the cart data.

propsTypeDescriptionExample
totalQuantityNumberTotal quantity of items in cart2
cartobjectCart object
linesArrayArray of cart line items (Cart API format)
lineItemsobjectArray of line items in cart (legacy format)
cartTotalPriceNumberTotal price of cart70
cartTotalPricelwithCurrencyStringTotal price of cart with currencyRs. 70
cartSubTotalAmountNumberSubtotal amount of cart30
cartTotalSavingsNumberTotal savings of cart40
cartTotalSavingsWithCurrencyStringTotal savings of cart with currencyRs. 40
cartTotalPayableStringTotal payable amount of cartRs. 30
cartTotalPayableWithCurrencyStringTotal payable amount of cart with currencyRs. 30
cartDiscountSavingsStringDiscount savings of cart30
cartDiscountSavingsWithCurrencyStringDiscount savings of cart with currencyRs. 30
cartTotalSavingWithoutDiscountNumberTotal saving without discount of cart10
cartTotalSavingWithoutDiscountWithCurrencyStringTotal saving without discount of cart with currencyRs. 10
shippingFeeNumberShipping fee of cart0
shippingFeeWithCurrencyStringShipping fee of cart with currencyRs. 0
isFreeShippingBooleanIs free shipping of carttrue
openCheckoutFunctionOpen checkout<button onClick={openCheckout}>Checkout</button>
canCheckoutBooleanCan checkouttrue
setCanCheckoutFunctionSet can checkout setCanCheckout(false);
checkoutLoadingBooleanCheckout loadingfalse
isCheckoutButtonLoadingBooleanIs checkout button loadingfalse
deliveryGroupsArrayDelivery groups from cart
discountApplicationsArrayDiscount applications from cart
cartErrorMessagesArrayCart validation error messages
firstProductIdStringID of the first product in cart
shareCartFunctionShare cart with messageshareCart({ message: 'Check out my cart!' })
addCartDeliveryAddressFunctionAdd delivery address to cartaddCartDeliveryAddress(address)

Usage:

import { useCart } from '@appmaker-xyz/shopify';
const { cart, setCanCheckout, shareCart, addCartDeliveryAddress } = useCart({ onAction }); // You can get the above props from this hook

image