Custom JavaScript
Run your own code on your store when a customer checks out with store credit, for example to block some carts.
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 = falseto stop the checkout, for example after showing a message.
Add your code
- In CreditsYard, go to Integrations › Custom JavaScript.
- Write your code in Before checkout, or open an example under Examples and click Add to code.
- Adjust the example, for example the amount or the selector.
- Click Save, then test a checkout with credit on your store.

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?
Thanks! Tell us what's missing.