Manually add a subscription

Posted in

Hi, can I take a user, add a subscription and set an expiration date?

i.e. User Mark Cuban registers and wants to have a free 3 month subscription.
Can I create this subscription manually and have it expire in 3 months?
When Mark looks at his user profile, he sees the subscription and the correct expiration date.
He gets all the benefits and can renew after 3 months if the relationship continues.

Thanks,

Ian

3 Responses to Manually add a subscription

  1. Ian August 25, 2015 at 5:43 pm #

    Antonio B. thank you for the help. This looks like it would apply to any user that registers right?
    I still want registered users to signup for one or more levels of subscription.

    I have 50 users and I just want to give one (1) of them a subscription manually.

    Sorry if I was not clear.

    Ian

    • antonio August 26, 2015 at 7:56 am #

      Yes, the code creates a subscription when a new user is registered.
      Don’t worry, here the improved code. When you edit an user profile and update it, then the subscription is created, so you only need:
      – Add this code (You need to change/remove/duplicate the piece of code relating to group).
      – Edit the user profile and update it.
      – And remove this code.
      Kind Regards,
      Antonio B.

  2. antonio August 25, 2015 at 7:43 am #

    Hi Ian,
    you could use the ‘user_register’ hook to create your subscription manually when a new user is registered, for example:
    add_action( 'user_register', 'my_subscription_user_register', 10, 1 );
    function my_subscription_user_register ( $user_id ) {
    $map = array(
    'user_id' => $user_id,
    'processor' => 'user_register',
    'reference' => 'Ref-' . $user_id,
    'last_payment' => date( 'Y-m-d H:i:s', time() ),
    'frequency' => 3,
    'frequency_uom' => Groups_Subscription::MONTH,
    'status' => Groups_Subscription::STATUS_ACTIVE
    );
    $subscription_id = Groups_Subscription::create( $map );
    }

    If you add this code in your functions.php file, it should work fine.
    Really I haven’t test to renew this subscription, please try this before (for example changing ‘frecuency’ to 1 and ‘frecuency_uom’ to Groups_Subscription::DAY).
    Kind regards,
    Antonio B.

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share