Page 1 of 1

Where paste paypal code for post/page restriction?

PostPosted: November 18th, 2011, 3:35 pm
by Dave72
Hi Guys,
excuse me for my bad english... I've installed s2member plugin, and it is a great plugin. I've setup specific post/page restriction for a specific post. But, I've a question: where must be paste the paypal code? I've setup membership page for subscribe members level Premium, when posts are filtered by a category restriction (called Premium). If I paste my code for specific post (for buy now) in this page, this code is visible for all users, and users could suppose that this code is a option for each post then for a specific post! Is it possible, when user get the specific post, to redirect him in a different page (instead of membership page) where I'll paste "buy now" paypal code? Else, is possible paste the paypal code in the specific post, so that user get the post, see the code instead the post content?
I try to search this option in s2member, but nothing. I watched tutorial videos, but my english is very poor... Sorry!
Thanks for your help!

Re: Where paste paypal code for post/page restriction?

PostPosted: November 19th, 2011, 4:29 am
by Dave72
Anyone answer? Thank you... :(((

Re: Where paste paypal code for post/page restriction?

PostPosted: November 19th, 2011, 7:08 pm
by Raam Dev
Hello Dave72,

If you want to redirect Specific Post/Pages to a separate purchase page (instead of using the Membership Options page), you will need to create a WordPress Page Template for your Membership Options Page and then add PHP code to the top of that template.

(You could also insert this code into your theme's page.php template, but it's cleaner to create a separate Page Template.)

The comments in the code below should explain how it works. Basically you need to detect when someone is being redirected to the Membership Options Page, determine which Specific Post/Page they were trying to access (using the page/post ID), and then redirect them to the correct page where they can purchase that Specific Post/Page with a Buy Now button (you'll need to create the purchase page for each Specific Post/Page and add the correct URLs to the code).

Code: Select all

<?php
// Check if this is a redirect from a restricted page
if(isset($_GET['s2member_seeking'])) { $url_attempt = $_GET['s2member_seeking']; }
    if($url_attempt){
        // Extract the Specific Post/Page ID that the user is attempting to access
        $url_attempt = str_replace(" ", "", $url_attempt);
        $id_attempt = explode("-", $url_attempt);
        $id_attempt = $id_attempt[1];
        
        if
(is_numeric($id_attempt)){
                // Check if the Specific Page/Post ID is one that 
                // we want to redirect to its own Purchase Page.
                // You can add new case statements for every page
                // that you want to redirect. Make sure the case
                // statement ends with break;
                switch($id_attempt) {
                    case "12214": // Specific Page/Post ID
                        $purchase_page = "http://example.com/purchase-page-for-12214/"; // Purchase page
                        break;
                        
                    case 
"12315": // Specific Page/Post ID
                        $purchase_page = "http://example.com/purchase-page-for-12315/"; // Purchase page
                        break;                        
                        
                    default
: // Always leave this here
                        $purchase_page = "";
                        break;
                }
                
                
// If we need to redirect
                if(trim($purchase_page) != "") {
                    
                    
// Use JavaScript to redirect to the correct purchase page
                    ?>
                    
                    <script type="text/javascript">
                    <!--
                    window.location = "<?php echo $purchase_page; ?>";
                    //-->
                    </script>
                    
                    <?php
                
}
                
            
}
        } 
?>



Once you create the page template and add this code, you will need to assign that page template to your Membership Options Page: Toward the bottom of the Write > Page administration panel is a drop-down labeled "Page Template"; from there you can select which Template will be used when displaying this particular Page.

If you're not familiar with WordPress Page Templates, you should read more about them here: http://codex.wordpress.org/Pages#Page_Templates

You can also read more about the variables available to the Membership Options Page here: WP Admin -> s2Member -> API / Scripting -> Membership Options Page / Variables.

Please let me know if this works for you! :)

Re: Where paste paypal code for post/page restriction?

PostPosted: November 20th, 2011, 1:19 pm
by Dave72
Hi Raam!
Thank you so much!!!!
Your code function for me, but I've altered it.

I've used if function instead the switch function, and I've filtered $id_attempt through category "Premium" to get the correct id post/page for buynow. Here my code:

Code: Select all

...

   if(!in_category('premium', $id_attempt)) {$purchase_page = "uri_buynow_page_purchase"; }
            else  $purchase_page = "uri_default_membership_page_purchase";

...



$id_attempt extract all posts subjected to restriction without any difference about restriction type (i.e. category restriction). I've used in_category() wp api function for filtered posts. In other words, when I insert the post ID in Specific Post/Page Access Restrictions, the code check if the post is in category "Premium" or not. If not and it is subjected to specific restriction, make redirection in the correct purchase page.

Thank You!!! :)

Re: Where paste paypal code for post/page restriction?

PostPosted: November 20th, 2011, 3:45 pm
by Raam Dev
Excellent! I'm glad it worked out for you! :)

And thank you for sharing your code modifications!