Chord OMS
...
SDK Reference
useCart
15 min
the usecart hook returns information about the current shopping cart, and functions for creating and updating the shopping cart example import { usecart } from ' /hooks/actions' const { cart, addpromocode, addtocart, applygiftcard, checkout, loadcart, modifyquantity, removefromcart, removegiftcard, removepromocode } = usecart() returns the usecart hook returns an object with these properties 189,554 trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type functions addpromocode the addpromocode function applies a promo code to the current order arguments addpromocode(promocode) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns promise\<void> a promise that resolves when the promo code has been applied to the order and the cart object has been updated to reflect the promo code example import { usecart } from ' /hooks/actions' const { addpromocode } = usecart() const promocode = '50off' await addpromocode(promocode) addtocart the addtocart function adds a product variant to the current order arguments addtocart(variantid, quantity, placement, position, customattributes) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns promise\<void> a promise that resolves when the new line item has been added to the cart example import { usecart } from ' /hooks/actions' const { addtocart } = usecart() const variantid = '123' const quantity = 1 await addtocart(variantid, quantity) applygiftcard the applygiftcard function applies a gift card to the current order arguments applygiftcard(giftcardcode) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns promise\<void> a promise that resolves when the gift card has been applied to the order and the cart object has been updated to reflect the gift card example import { usecart } from ' /hooks/actions' const { applygiftcard } = usecart() const giftcardcode = 'xxxyyyzzz' await applygiftcard(giftcardcode) checkout the checkout function redirects the browser to shopify checkout arguments none returns promise\<void> a promise that resolves when the browser has been redirected to shopify checkout example import { usecart } from ' /hooks/actions' const { checkout } = usecart() await checkout() loadcart the loadcart function loads the current cart based on the current browser session this is automatically called on every page load and with every other usecart method arguments none returns promise\<void> a promise that resolves when the cart object has been added to redux example import { usecart } from ' /hooks/actions' const { loadcart } = usecart() await loadcart() modifyquantity the modifyquantity function modifies the quantity of a line item in the cart arguments modifyquantity(lineitemid, quantity) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns promise\<void> a promise that resolves when the cart object has been updated in redux example import { usecart } from ' /hooks/actions' const { modifyquantity } = usecart() const lineitemid = '123' const quantity = 2 await modifyquantity(lineitemid, quantity) removefromcart the removefromcart function removes a line item from the cart arguments removefromcart(lineitemid) 179,154,410 2 true left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns promise\<void> a promise that resolves when the cart object has been updated in redux example import { usecart } from ' /hooks/actions' const { removefromcart } = usecart() const lineitemid = '123' await removefromcart(lineitemid) removegiftcard the removegiftcard function removes a gift card from the current order arguments removegiftcart(appliedgiftcardid) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns promise\<void> a promise that resolves when the cart object has been updated in redux example import { usecart } from ' /hooks/actions' const { removegiftcard } = usecart() const giftcardid = 'xxxyyyzzz' await removegiftcard(giftcardid) removepromocode the removepromocode function removes an applied promo code from the order arguments removepromocode(promocode) trueleft unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type returns promise\<void> a promise that resolves when the promo code has been removed from the order and the cart object has been updated to reflect the promo code example import { usecart } from ' /hooks/actions' const { removepromocode } = usecart() const promocode = '50off' await removepromocode(promocode)