Direct free trial option

I am not so experienced in PHP, but I have managed to create a shortcode that would allow me to give users a direct 15 day free trial without having to use the paypal button. For some reason, I am not able to alter the user profile fields of user level and EOT although I know I am using the proper coding, so I have given that up for now.

It is senseless to make a user go through paypal to get a free(actually $0.01) trial. There should be an easy way to do this like what I am trying to do: I just want a button my user can click and get a free trial access period to my app page: meaning set their access level to 2, and set their eot for 2 weeks from today, when they would return to level 0. It should not require the massive amount of time I researched the php hooks and shortcode methodologies to make this happen. While these are interesting subjects, I just want to create a direct, no obligation way a user can try out my application before paying for a membership. I don’t know why my code would not work except to guess that those fields are protected from direct editing somehow. Why don’t the docs say anything about this?
I cannot make update_user_option or user->set_role() do what they are supposed to do regarding only those particular fields. Other fields work fine, I can display and edit the standard data fields just fine. Please help.

Hi Terry.

I’m not sure I understood what you tried, but I understand what you’re trying to do.

With s2Member Pro forms, it’s easy to register a user for free at a higher level with an EOT time set. https://s2member.com/kb-article/how-can-i-offer-a-fixed-term-free-registration/

Otherwise, with a bit of code, you could do it too. On the page with your premium content, you could use a condition that checks the user’s registration time, and display the content to him only if he’s in his first two weeks, or if he has the paid level. WP Admin > s2Member > API / Scripting > s2Member Content Dripping

I hope that helps. :slight_smile:

What I tried is using a php snippet attached to a button using a shortcode link to the snippet.
This is kind of what I was trying in the php snip:

<?php $user_id = get_current_user_id(); $user = get_current_user(); $user->set_role( 2 ); $user->add_cap('access_s2member_level2'); $now = strtotime('now'); update_user_option($user->id, 's2member_auto_eot_time', $now + (15 * DAY_IN_SECONDS)); /** update_user_option( $user_id, 'show_admin_bar_front', false ); */ ?>

I was able to change basic profile fields like name ,company email etc…, could read the member level and eot time,
but I was unable to change the eot or member level fields using this method that did work for changing the basic fields.
It was so discouraging as I did a lot of work to get to that point: running PHP from a button click to do automated profile editing.

I will look into doing the eot comparison, but the whole point is to give access to the page ONLY if they are permitted. Not to let them go to the page and be denied at that point. Putting the code on my content page would require that they can get to the page, which defeats the access control system. If I could do this on the subscription page and actually change the member level temporarily it would be acceptable.

I really want to be able to make a Free Trial button on my subscription page using the method above, so instead of going through the whole paypal ordeal (a very uneasy and misleading process for a new user) it can all be handled internally. I want to provide users direct access to my app page to try before ANY reference of the payment process.

This article will help you with the level role change. https://s2member.com/kb-article/rolescapabilities-via-php/

For the level try $user->set_role('s2member_level2');

I’m not sure why the EOT set is not working for you, though. I’d probably calculate the time first and then set the EOT.

But like I said earlier, you could use the free registration pro-form, that one doesn’t show any payment options, it’s just a signup form that lets you set the level and EOT time for the new user. WP Admin > s2Member Pro > PayPal Pro-Forms > Free Registration Form

:slight_smile: