Your cart is currently empty!
Manually add a subscription
—
by
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
Posted in Groups PayPal
Comments
3 responses to “Manually add a subscription”
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
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.
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.