The PMPro_Discount_Code class holds information about PMPro discount codes and can be used to create, update, delete, or get information about discount codes.

Example of the PMPro_Discount_Code Class

To instantiate this class, use:

$discount_code = new PMPro_Discount_Code();

Constructor Parameters

string $code = null

The discount code that should be used to retrieve this object. If null, a blank PMPro_Discount_Code object is created. Some examples:

$discount_code = new PMPro_Discount_Code( '1' );

This code would retrieve a PMPro_Discount_Code object for discount ID 1:


$discount_code = new PMPro_Discount_Code( 'S0DE87D5119' );

This code would retrieve a PMPro_Discount_Code object for discount code S0DE87D5119:


Properties

string code

Unique identifier for this discount code.

string starts

The starting date of when this discount code will be valid from.

string expires

The expiration date of when this discount code will be valid up to.

string uses

The number of times this discount has been used.

array levels

The levels that this discount code applies to along with the changes the discount code applies.

string $discount_code->levels['initial_payment']

The initial amount a member would be billed upon signing up for a membership.

string $discount_code->levels['billing_amount']

The recurring amount a member would be billed upon signing up for a membership.

string $discount_code->levels['cycle_number']

The number of billing cycles for that level.

string $discount_code->levels['cycle_period']

The billing cycle period. Possible values are “Day”, “Week”, “Month”, and “Year”.

string $discount_code->levels['billing_limit']

The maximum number of times this level can bill a customer.

string $discount_code->levels['custom_trial']

Specifies if a custom trial is active for that level.

string $discount_code->levels['trial_amount']

The trial amount that a member would be billed for.

string $discount_code->levels['trial_limit']

The length of the trial for the level

int $discount_code->levels['expiration_number']

The number after how long a level is active would expire after. Example: 2 Months

string $discount_code->levels['expiration_period']

The expiration period. Possible values are “Day”, “Week”, “Month”, and “Year”.

Public Methods

get_discount_code_by_id( $id );

Get the discount code object by ID

Parameters

string $id – The discount code ID

Returns

Object, the discount code object containing that specific discount code’s data. If not found, returns false.

Examples

$discount_code = new PMPro_Discount_Code();
$discount_code->get_discount_code_by_id( '1' );

get_discount_code_by_code( $code );

Gets the discount code object by the discount code

Parameters

string $code – The discount code

Returns

Object, the discount code object containing that specific discount code’s data. If not found, returns false.

Example

$discount_code = new PMPro_Discount_Code();
$discount_code->get_discount_code_by_code( 'S0DE87D5119' );

get_empty_discount_code();

Parameters

Gets an empty but complete discount code object.

$discount_code = new PMPro_Discount_Code();
$discount_code->get_empty_discount_code( 'S0DE87D5119' );

Returns

Object, containing an empty discount code template.


get_discount_code_billing( $code );

Parameters

string $code – The discount code

Returns

Object, The discount code object with the billing details associated with each level in the discount code.

Examples

$discount_code = new PMPro_Discount_Code( 'S0DE87D5119' );
$discount_code->get_discount_code_billing( 'S0DE87D5119' );

save()

Method used to save the discount code when creating or updating a discount code.

Returns

The recently saved discount code object.

Examples

$discount_code = new PMPro_Discount_Code();
$discount_code->code = 'XYZ1234';
$discount_code->start = '2023-12-01';
$discount_code->expires = '2023-12-31';
$discount_code->save();

Action and Filter Hooks

Was this article helpful?
YesNo