rcp_add_membership()

Add a new membership record.

Parameters:

  • $args (array) - An array of arguments.
    • $customer_id (int) - Required. ID of the customer this membership is for.
    • $object_id (int) - Required. ID of the membership level this membership is for.
    • $object_type (string) - Optional. The type of object. Default is `membership`.
    • $currency (string) - Optional. Currency used for the membership. Default is the currency specified in Restrict > Settings > Payments.
    • $initial_amount (string) - Optional. Amount charged on initial registration. Default is `0.00`.
    • $recurring_amount (string) - Optional. Amount charged for renewals. Default is `0.00`.
    • $created_date (string) - Optional. Date the membership was created in MySQL format. Default is the current date and time.
    • $trial_end_date (string) - Optional. Date the integrated free trial ends. If omitted, this will be set automatically based on the customer's free trial allowance and whether or not the associated object ID has a built-in trial.
    • $expiration_date (string) - Optional. Date the membership expires or renews, in MySQL format. Use `none` if the membership never expires. If omitted, this is auto calculated based on the associated object ID.
    • $auto_renew (bool) - Optional. TRUE if this membership has auto renew enabled, FALSE if it does not. Default `false`.
    • $times_billed (int) - Optional. Number of times this membership has been billed for so far. Default `0`.
    • $status (string) - Optional. Status of the membership. Accepts: pending, active, cancelled, expired. Default `pending`.
    • $gateway_customer_id (string) - Optional. Gateway customer ID. Default empty.
    • $gateway_subscription_id (string) - Optional. Gateway subscription ID. Default empty.
    • $gateway (string) - Optional. Slug of the gateway. Default empty.
    • $signup_method (string) - Optional. Signup method. Accepts: live, manual, imported. Default `live`.
    • $subscription_key (string) - Optional. Unique subscription key for this membership. Default empty.
    • $notes (string) - Optional. Notes for the membership. Setting this manually here is not recommended. Default empty.
    • $upgraded_from (int) - Optional. ID of a membership this one was upgraded from. Default empty.
    • $disabled (int) - Optional. Whether this membership is disabled (1) or enabled (0). Default `0`.

Return values:

  • (int|false) - ID of the newly created membership on success, or false on failure.

Example:

Creates a new, active membership for customer #50 on membership level #2:

$membership_id = rcp_add_membership( array(
    'customer_id' => 50,
    'object_id' => 2,
    'status' => 'active'
) );