Account Funds developer reference

The shortcode, widget, REST API fields, templates and hooks for working with Account Funds in code.

Beka Rice Avatar

Written by

Last updated


Account Funds gives you a shortcode and a widget for showing a customer’s store credit balance, adds balances to the WooCommerce REST API, and lets you override its customer-facing templates. This page covers those and the hook and order meta that are part of its public interface.

Store credit balance shortcode

[store_credit_balance] outputs a customer’s available store credit balance, formatted in your store’s currency by default, such as $50.00. Use it in a page, a post, or a Shortcode block. [get-account-funds] is an older name for the same shortcode and takes the same attributes.

[store_credit_balance]
AttributeDefaultWhat it does
customerThe logged-in userThe user ID whose balance to show
currencyYour store currencyThe currency code of the balance to show
formattedtrueWhether to format the amount with the currency symbol and decimals

Some things to know:

  • The balance is the available balance, which leaves out credit held by unpaid orders.
  • To output the bare number, use formatted="0". Any other value, including formatted="false", still outputs the formatted price.
  • A logged-out visitor sees a zero balance, such as $0.00, not an empty string. To show the balance only to customers, put the shortcode where only logged-in users see it.
  • With customer, the page shows that user’s balance to everyone who can view it, so use it only on pages restricted to staff.

If your site caches pages for logged-in users, a cached page can show one customer’s balance to another. Exclude pages that use the shortcode from the cache, or serve logged-in users uncached pages.

To link the balance to the customer’s store credit tab, point the link at the tab’s address, /my-account/account-funds/ by default:

<a href="/my-account/account-funds/">Your store credit: [store_credit_balance]</a>

My Account Funds widget

The My Account Funds widget, under Appearance » Widgets or as a legacy widget block, shows logged-in customers "You currently have $X worth of store credit in your account." with a View deposits button that opens their My Account store credit tab. Its title defaults to "My Store credit", using your plural label. Logged-out visitors don’t see it.

REST API

The WooCommerce REST API’s customer endpoints, such as GET /wp-json/wc/v3/customers/<id>, include a store_credit object:

"store_credit": {
  "balances": [
    {
      "currency": "USD",
      "balance": 50,
      "available_balance": 35
    }
  ]
}

balance is the current balance and available_balance leaves out credit held by unpaid orders. The field is read-only, and there are no endpoints for transactions.

The Cart and Checkout blocks talk to Account Funds through a Store API extension named account-funds, which the blocks use to apply and remove credit.

Hook: wc_account_funds_customer_funds_increased

An action that fires when staff raise a customer’s balance: by saving a higher Amount on the user profile, or by adding a credit in Account funds » Wallets with Notify customer ticked. Account Funds uses it to send the Store credit increased email.

add_action( 'wc_account_funds_customer_funds_increased', function ( $user_id, $previous_balance, $new_balance ) {
	// Your code, for example a CRM update.
}, 10, 3 );
ParameterTypeDescription
$user_idintThe customer’s user ID
$previous_balancefloatThe balance before the change
$new_balancefloatThe balance after the change

Order meta

Orders that used store credit carry these meta keys, which you can read in exports or custom reports:

Meta keyWhat it holds
_funds_usedThe store credit applied to the order
_funds_removedWhether that credit has been settled: debited from the customer’s balance, or released if the order failed or was cancelled
_funds_refundedStore credit returned to the customer for the order
_funds_versionThe Account Funds version that last processed the order’s store credit

Treat them as read-only; Account Funds manages them as the order changes.

Template overrides

Copy a template from the plugin’s templates/ folder to the woocommerce/ folder in your theme, keeping its path, to override it:

  • myaccount/account-funds.php: the My Account store credit tab.
  • myaccount/topup-form.php: the top-up form.
  • myaccount/recent-deposits.php: the Recent deposits list.
  • myaccount/account-funds/topup-in-cart-notice.php: the notice shown in place of the top-up form while a top-up is in the cart.
  • emails/customer-store-credit-awarded.php, emails/customer-account-funds-increase.php, emails/customer-store-credit-expiring.php and emails/admin-reward-status-changed.php, plus their plain text versions in emails/plain/.

For example, to change the My Account tab, copy templates/myaccount/account-funds.php to yourtheme/woocommerce/myaccount/account-funds.php. Check your overrides after updating Account Funds, since templates can change between versions.

Keep learning