Developers

Code

Whenever you're dealing with a code in your template, you're actually working with a Code object.

Properties

id

Type: int|null

ID of the code.

voucherId

Type: int|null

The Voucher ID the code is generated for.

voucher

Type: verbb\giftvoucher\elements\Voucher|null

The Voucher the code is generated for.

voucherType

The voucher's type the code is generated for.

orderId

Type: int|null

The Order (opens new window) ID where the parent voucher was originally purchased from.

order

Type: craft\commerce\elements\Order|null

The Order (opens new window) where the parent voucher was originally purchased from.

lineItemId

Type: int|null

The Line Item (opens new window) ID in the order where the parent voucher was originally purchased from.

lineItem

Type: craft\commerce\models\LineItem|null

The Line Item (opens new window) in the order where the parent voucher was originally purchased from.

codeKey

Type: string|null

The generated, unique code used for redeeming this amount.

originalAmount

Type: float|null

When the voucher is purchased initially, the amount is stored under this value. This cannot be updated.

currentAmount

Type: float|null

The unredeemed amount recorded for the code. Because vouchers can be redeemed multiple times, this amount can be used all at once or across several orders. Active checkout holds reduce the amount currently available without changing this value until the order completes.

expiryDate

Type: DateTime|null

The date this code will no longer be available for use.

Methods

getCpEditUrl()

Returns: string|null

The url to edit this code in the control panel.

getRedemptions()

Returns: array

Shows a list of all redemptions for that code. This keeps track of what orders and products this code has been used against.

getAvailableAmount()

Returns: float

Returns the amount available to a new checkout after active holds are deducted from currentAmount.

getHeldAmount()

Returns: float

Returns the total value currently held by unresolved checkouts.

getReservations()

Returns: array

Returns the active checkout holds for the code. A hold remains active until its order completes, an explicit decline releases it or an administrator releases it after reviewing the payment state.

Last updated: Sept 29, 2026, 4:02:00 PM