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.

PHP API

In PHP, get a customer’s wallet with \Kestrel\Account_Funds\Store_Credit\Wallet::get( $customer ), passing a user ID, an email address, a user or customer object, or an order. The wallet’s balance() method returns the customer’s total balance, and available_balance() returns the amount they can spend now, which leaves out credit held by unpaid orders.

To change a balance, pass a \Kestrel\Account_Funds\Store_Credit\Wallet\Transaction to the wallet’s credit() or debit() method. The transaction is recorded in the ledger, and an exception is thrown when it can’t be recorded, such as a debit larger than the customer’s balance:

use Kestrel\Account_Funds\Store_Credit\Wallet;
use Kestrel\Account_Funds\Store_Credit\Wallet\Transaction;
use Kestrel\Account_Funds\Store_Credit\Wallet\Transaction_Event;

Wallet::get( $user_id )->credit( Transaction::seed( [
	'amount'   => 10.00,
	'event'    => Transaction_Event::USER_ACTION,
	'event_id' => get_current_user_id(),
	'note'     => 'Goodwill credit',
] ) );

The older Users functions for reading and changing balances are deprecated. Use the wallet instead.

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

Filter: wc_account_funds_paid_order_statuses

Filters the order statuses Account Funds treats as paid, for cashback, purchased store credit and store credit applied at checkout. The default is Processing and Completed. Add a custom status slug, without the wc- prefix, if your store marks paid orders with one.

add_filter( 'wc_account_funds_paid_order_statuses', function ( $statuses ) {
	$statuses[] = 'paid-awaiting-shipment';

	return $statuses;
} );

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 (which receives $reward, the reward that generated the award, when a single reward accounts for the whole amount), 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