Skip to content

POS refunds and Flow actions are live7-day free trial

Install CreditsYard (opens the Shopify App Store)

Custom JavaScript

Run your own code on your store when a customer checks out with store credit, for example to block some carts.

2 min read · Updated December 4, 2026

Open in CreditsYard

Add your own rules to the store credit checkout on your storefront, without editing your theme.

How it works

  • Your code runs in the customer's browser when they click to check out with store credit in the store credit widget.
  • It runs before CreditsYard sends them to checkout.
  • Set StoreCredit.proceedToCheckout = false to stop the checkout, for example after showing a message.

Add your code

  1. In CreditsYard, go to Integrations › Custom JavaScript.
  2. Write your code in Before checkout, or open an example under Examples and click Add to code.
  3. Adjust the example, for example the amount or the selector.
  4. Click Save, then test a checkout with credit on your store.
The Custom JavaScript page with the Before checkout editor and the examples list
The Custom JavaScript page with the Before checkout editor and the examples list

Variables you can use

Variable What it is
StoreCredit.cart The current Shopify cart. Prices are in cents, for example StoreCredit.cart.total_price.
StoreCredit.customerCredit The customer's balance, in your store currency.
StoreCredit.proceedToCheckout Set to false to stop the checkout.
StoreCredit.closeWidget() Closes the store credit widget.

Example: minimum order amount

var minimum = 50; // In your store currency
if (StoreCredit.cart.total_price / 100 < minimum) {
    alert('Store credit can be used on orders of ' + minimum + ' or more.');
    StoreCredit.proceedToCheckout = false;
}

Ready-made examples

The Examples list on the page includes:

  • Require enough credit for the whole cart
  • Minimum order amount
  • Block gift cards, or exclude a product type
  • Check out from the cart page only
  • Require a field (like a delivery date) or a terms checkbox
  • Wait for a delivery or pickup app, like Zapiet
  • Track checkouts with credit in Google Tag Manager or GA4
  • Change the widget's error messages

Good to know

  • The code only runs for checkouts started from the store credit widget, not Shopify's normal checkout button.
  • Test changes on your store after saving. A JavaScript error can stop checkout with credit.
  • Most limits need no code: check Limits, tax and shipping first.
Was this guide helpful?