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 flat to 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 active to indicate the discount may be used, or disabled to 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. 0 to create a recurring discount that applies to all payments in a membership, or 1 to create a one-time discount that only applies to the first payment. Default 0.

Return values:

  • (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
) );
Powered by Zendesk