Voucher
Whenever you’re dealing with a voucher in your template, you’re working with a Voucher object. A voucher is the Commerce purchasable customers buy, and each purchase creates one or more Code objects that customers redeem. You can fetch vouchers with a voucher query.
Properties
The ID of the voucher.
The voucher’s title.
The voucher’s title. This is the same as title, and is available because Commerce refers to a purchasable’s name.
The URL of the voucher’s own page. This is null when its voucher type has no URI format.
The ID Commerce uses for the voucher as a purchasable, which is the same as its id. Use it when adding the voucher to the cart.
The voucher type the voucher belongs to.
The ID of the voucher’s voucher type.
The price of the voucher. When the voucher has a custom amount, the customer’s chosen amount is used instead.
Whether customers choose the voucher’s amount when they buy it, rather than paying its set price. See Custom Amounts.
The voucher’s SKU, which identifies it in Commerce.
The voucher’s status, which is live, pending, expired or disabled. An enabled voucher is pending before its post date, expired after its expiry date and live in between.
Whether the voucher is enabled.
The ID of the tax category Commerce uses when calculating tax on this voucher.
The tax category Commerce uses when calculating tax on this voucher.
The ID of the shipping category Commerce uses when calculating shipping for this voucher.
The shipping category Commerce uses when calculating shipping for this voucher.
The date the voucher goes on sale.
The date the voucher stops being available for sale. This is null when it doesn’t expire.
Methods
Returns the URL to edit this voucher in the control panel.
Returns: string
Returns the URL to download the PDF of the codes bought in a Commerce line item. Use it on an order confirmation page or email to link to the customer’s voucher PDF. See PDF Vouchers.
Returns: array
Returns the Code objects created for a Commerce line item, one for each voucher bought in it.
Returns the voucher itself. Commerce templates often call purchasable.product, so this lets the same template code work for vouchers.