latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Custom Coupon Code

Home Forums Community Forum Custom Coupon Code

This topic contains 12 replies, has 2 voices. Last updated by  Abner Garcia 4 years ago.

Topic Author Topic
Posted: Wednesday Dec 5th, 2012 at 3:18 pm #33608
Abner Garcia
Username: Abner7g

Here is the situation. I would place a promotional discount in a external well know online coupon website for a special access to a restricted page in my website. This page will have a eGreeting plugin function so my visitors send christmas eCard by email for their love ones. The logistic that I’m thinking is:

1. Visitor buy the offer in the well know coupon website
2. Visitors receive a transaction code once they complete the sale.
3. Visitors register in my website and then insert the transactions code when they reach my special restricted page (I want to use this transaction code as my custom coupon code configured in my s2m settings to give access to the restricted page)

Can you imagine what would be the shortcode or script to create this special custom coupon code? It will be better if I can restrict this access somehow to a limited amount of time or onces the visitor leave the page or hit the send eCard button in the page.

Thank you very much!!

List Of Topic Replies

Viewing 12 replies - 1 through 12 (of 12 total)
Author Replies
Author Replies
Posted: Wednesday Dec 5th, 2012 at 3:40 pm #33614
Bruce
Username: Bruce
Staff Member

Hi Abner,

It sounds like it might be in your best interest to use Dashboard -› s2Member® -› PayPal® Pro Forms -› Specific Post/Page (Buy Now) Forms instead of standard s2Member forms. This way s2Member can handle almost all of functionality for you.

Otherwise, you may want to set up API Notifications (Dashboard -› s2Member® -› API / Notifications -› Payment Notifications) to handle this.

Posted: Wednesday Dec 5th, 2012 at 5:36 pm #33626
Abner Garcia
Username: Abner7g

Thanks Bruce I will definitely look up on this but in this case I will no have a transaction in my page. Visitors will buy the coupon with an external website. They will come with their transaction code from the sale. That transaction code is the one that I need to use to gave access to the visitors into my restricted page. They will first register free in my website and then when they press the restricted page link they would be asked to insert the transaction code from the sale. So in other words I should consider some code like “coupon 01-1000” Thanks!!

Posted: Wednesday Dec 5th, 2012 at 6:16 pm #33630
Bruce
Username: Bruce
Staff Member

Hi Abner,

It sounds like you will need to set some custom code up outside of s2Member. Perhaps you could set up the page to be protected with a custom capability, and add or remove the ccap whenever it is needed (i.e. when the user puts in a valid coupon, and when they click the submit button on your eCard). You can do this by getting the user’s ID, then doing this:

<?php
$user = new WP_User($id);

$user->add_cap('access_s2member_ccap_test'); // Adds custom capability "test"
$user->remove_cap('access_s2member_ccap_test'); // Takes it away

For verification of the coupon that the users gets sent, the website you are receiving the coupon from most likely has an API that you can check it with. You will need to use this API to check the code and then add the capability. Then, you will want to remove the capability later.

Posted: Wednesday Dec 5th, 2012 at 9:56 pm #33647
Abner Garcia
Username: Abner7g

Great… well about the API I’ll have to find out. They are Groupon.com. So using this code the visitor has tu put his code befores he can open the page and then hi validates his ID once he hits the send button and the access will be remove once the visitors close the page, am I right?

Posted: Thursday Dec 6th, 2012 at 1:14 pm #33717
Bruce
Username: Bruce
Staff Member

They are Groupon.com.

If that’s the case, I believe you won’t need an API to check the coupon, because you’ll know what the coupon’s code is already, correct?

So using this code the visitor has tu put his code befores he can open the page and then hi validates his ID once he hits the send button and the access will be remove once the visitors close the page, am I right?

Yes, that’s correct. If my above comments were correct, you should probably set another custom capability after the coupon is used such as “test_used” so that you can tell if a user has already used the coupon code before.

Posted: Thursday Dec 6th, 2012 at 3:38 pm #33750
Abner Garcia
Username: Abner7g

Wow adding that cap line will be much better. Can I use the script you wrote above with the new test_used line. I believe that I should change “test” with my custom capability name write. I will kindly ask if you can write this script for me. Thanks you very much Bruce!!

Posted: Thursday Dec 6th, 2012 at 3:55 pm #33759
Bruce
Username: Bruce
Staff Member

Hi Abner,

When the user enters the coupon, you should do the following (replacing the ccap “test” with whatever ccap you’re using):

<?php
$user = new WP_User(get_current_user_id());

$user->add_cap('access_s2member_ccap_test'); // Adds custom capability "test"

When the user presses the button and should no longer have access, do this (again, replacing “test”):

<?php
$user = new WP_User(get_current_user_id());

$user->remove_cap('access_s2member_ccap_test'); // Takes it away
$user->add_cap('access_s2member_ccap_test_used'); // Tells us that the user has used a coupon already.

Make sure to use something like this where you have your form to input the coupon (replace “test”):

<?php if(current_user_can('access_s2member_ccap_test_used')) { ?>
	You are not allowed to input a coupon more than once.
<?php } else { ?>
	Normal Content (the form to enter the coupon)
<?php } ?>
  • This reply was modified 4 years, 1 month ago by  Bruce. Reason: Replacing $id with get_current_user_id()
Posted: Friday Dec 7th, 2012 at 9:58 am #33896
Abner Garcia
Username: Abner7g

Everything is fantastic Bruce but I forgot to keep mentioning like my first post the fact that this is a plugin that I need to insert in a page or post by a shortcode. So I believe that my efforts still goes for the page management. Like we already mentioned to restricting the page access and onces the visitor fill in the form and hit the “send” button the script needs to restrict again the page from opening again using the same code like you already establish in your code.

Their’s another fact. Once the visitor hit the “send” button the page reload automaticly to display the “thank you and successfully sent message” in a new blank eCard form. But I’m thinking now that it doesn’t necessary needs to be a problem at all since the visitor has to put the transaction code in every new eCard form to send it so the page would be asking to enter the code and that’s the moment when the last line in your script make the action to verify a used transaction code, right?

Posted: Saturday Dec 8th, 2012 at 2:20 pm #33999
Bruce
Username: Bruce
Staff Member

But I’m thinking now that it doesn’t necessary needs to be a problem at all since the visitor has to put the transaction code in every new eCard form to send it so the page would be asking to enter the code and that’s the moment when the last line in your script make the action to verify a used transaction code, right?

If that’s the case this is much simpler. Just use that plugin’s features.

Posted: Saturday Dec 8th, 2012 at 2:24 pm #34001
Abner Garcia
Username: Abner7g

That’s the problem the plugin wasn’t made for sell eCards just give a free access to send them. So I have to manage to restrict the page from unregistered and unpaid visitor.

Posted: Saturday Dec 8th, 2012 at 2:32 pm #34005
Bruce
Username: Bruce
Staff Member

That’s the problem the plugin wasn’t made for sell eCards just give a free access to send them. So I have to manage to restrict the page from unregistered and unpaid visitor.

This seems like a good time to use custom capabilities. You will have to set up this custom code, though.

Posted: Tuesday Dec 18th, 2012 at 10:17 am #34939
Abner Garcia
Username: Abner7g

Agreed, I’m not too familiar with CCap custom codes other than CCap set up. I think that using the code that you wrote above for the page access is a great start but my concern is to limit the access with the same person and transaction coupon code with the page that holds the plugin code.

Viewing 12 replies - 1 through 12 (of 12 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.