Skip to main content
With the $wsVoucher module, you can use and display voucher data dynamically in the frontend. You can list redeemed vouchers, calculate the total value, and load details for individual vouchers. In this section, you will learn how to retrieve voucher data and display it in the basket or checkout.

Module overview

Example / excerpt of $wsVoucher
JSON output
Note: ƒ() denotes a function. Variables and methods overview

Templates

Voucher data can generally be loaded and displayed in any template. Entering or redeeming a voucher code is possible throughout the shop. However, it is most useful within the ordering process or in the basket.

Variables

$wsVoucher.vouchers

Returns a list of all vouchers that the customer has redeemed in the current basket.

$wsVoucher.totalValue

Returns the total value of the redeemed vouchers.

$wsVoucher.totalUsedValue

Returns the voucher value already deducted from the basket.

$wsVoucher.maximumCount

Returns the maximum number of vouchers that a customer may redeem at the same time.

Methods

$wsVoucher.load()

Loads a voucher by its ID. Signature
$wsVoucher.load(id)
Return value
Map - Voucher map with the voucher data.
Parameters Example that loads a voucher:
By using the $wsVoucher.load() function, various variables are available to retrieve and output voucher data. Below is an overview of which variables are available.

Voucher data (return value of $wsVoucher.load())

First, it is necessary to assign the map with the voucher data, as shown in the example above, to a local variable. This can then be used at various places in the template. JSON output
Variables overview

Actions

Actions for this module that trigger changes are documented separately in the “Actions” chapter: Voucher

Example for displaying voucher data

Voucher value

This example displays the value of the voucher.

Voucher type: percentage or fixed amount

This example checks and displays whether the voucher grants a percentage discount or a fixed amount.

Validity date of the voucher

This example displays the start and end date of a voucher’s validity.

Voucher currency

This example displays the currency in which the voucher was issued.

Display remaining amount of a voucher

This example displays the remaining amount that a partially used voucher still has.

Check voucher validity

This example checks whether the voucher is basically valid.

Show form only until the maximum number of vouchers has been redeemed

The form is only displayed if the number of vouchers already redeemed is less than the configured limit. If the limit is reached, the form is hidden and the customer receives a notice.
You can find more practical examples on the topic of vouchers here.