Note: This is part of the developer docs and is considered custom code.
Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.
If you need assistance with this, please reach out to our list of consultants for further assistance:
Add a new discount to the database.
- $args (array) - Array of arguments.
- $name (string) - Required. Name of the discount.
- $description (string) - Optional. Description of the discount.
- $amount (int|float) - Required. Amount to discount.
- $unit (string) - Required. Type of discount - either
%to indicate a percentage discount, or
flatto indicate a flat discount amount. This is used with $amount to build the full discount amount. Default
- $code (string) - Required. The code used during registration to apply this discount.
- $use_count (int) - Optional. The number of times the discount has been used so far. Default 0.
- $max_uses (int) - Optional. The maximum number of times the discount may be used. 0 indicates unlimited. Default 0.
- $status (string) - Optional. Status of the discount. Either
activeto indicate the discount may be used, or
disabledto indicate the discount may not be used. Default disabled.
- $expiration (string) - Optional. MySQL date representing when the discount expires. It may no longer be used after this date. Leave blank to never expire. Default blank.
- $membership_level_ids (array) - Optional. The array of membership IDs this discount may be used for. Leave blank to allow on all membership levels. Default empty array.
- $one_time (int) - Optional.
0to create a recurring discount that applies to all payments in a membership, or
1to create a one-time discount that only applies to the first payment. Default 0.
- (int) - ID of the newly created discount code on success.
- (WP_Error) - WP_Error object on failure.
Version added: 3.3
Create a one-time 50% off discount for Black Friday that expires December 1st at 11:59 pm.
$discount_id = rcp_add_discount( array( 'name' => 'Black Friday Sale', 'amount' => 50, 'unit' => '%', 'code' => 'black_friday_2019', 'expiration' => '2019-12-01 23:59:59', 'one_time' => 1 ) );