Restrict Content Pro

rcp_add_discount()

Coming soon: Restrict Content Pro is becoming Kadence Memberships. You may see both names used while we update the product, documentation, and customer experience.

Note: This content is provided as a resource within our developer documentation. Because custom code requires highly specific implementation, we encourage you to work with a qualified developer if you need guidance. You can find our recommended consultants here: https://codeable.io/developers/restrict-content-pro

Creates a discount code in the database.

Requires a unique code. Default status is disabled â€” set active for registration use. Percent discounts (unit = %) must be whole numbers from 1–100. unit is % or flat. Legacy arg subscription_id maps to membership_level_ids.

Actions: rcp_pre_add_discount, rcp_add_discount (after insert).

Parameters

$args (array) – Discount fields:

  • code (string) – Required. Unique code.
  • name (string) – Optional label.
  • description (string) – Optional.
  • amount (string|float) – Default: 0.00.
  • unit (string) – % or flat. Default: %.
  • status (string) – active or disabled. Default: disabled.
  • max_uses (int) – Default: 0 (unlimited).
  • use_count (int) – Default: 0.
  • expiration (string|null) – Optional expiration datetime.
  • membership_level_ids (array) – Level IDs this code applies to; empty = all levels.
  • one_time (int) – One-time use flag.
  • subscription_id (int) – Legacy; maps to a single level ID.

Return values

(int|WP_Error) – New discount ID on success; WP_Error if the code is missing, duplicated, the amount is invalid, or the insert fails.

Examples

$discount_id = rcp_add_discount(
	array(
		'code'                 => 'launch20',
		'name'                 => 'Launch 20% off',
		'amount'               => 20,
		'unit'                 => '%',
		'status'               => 'active',
		'membership_level_ids' => array( 2, 3 ),
	)
);

if ( is_wp_error( $discount_id ) ) {
	// Handle error.
}

Related: rcp_get_discount_by(), RCP_Discount.

Last updated: November 11, 2026
Was this page helpful?
Thanks for the feedback!