PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Custom thank you email per product?

s2Member Plugin. A Membership plugin for WordPress®.

Re: Custom thank you email per product?

Postby cassel » August 30th, 2011, 6:41 pm

For instance, search s2Member's source code for: ws_plugin__s2member_modification_email_sbj


Where is that? Looking at the article you refered me to, nothing looks like that so maybe it is INSIDE another category?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby cassel » August 30th, 2011, 10:49 pm

Still studying. I found the ws_plugin__s2member_modification_email_sbj . I still have a few question (if you are this patient with me) so i can apply all those helpful suggestions you are giving me.

- i am looking all over and i dont see where the $vars = array ()) is nor how to extract the information. I am probably not looking in the right place though since you are refering to those variables
- since the signup confirmation is apparently corrent (in the case of a new member), i cannot figure out which filter would refer to the process for existing members, unless it is a way to twist the SC filter itself?
- can i incorporate similar conditionals in the s2-hacks.php file as for the other s2member conditionals?

(that is all for now, but i'll be back, i am sure! )
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Cristián Lávaque » August 31st, 2011, 2:13 am

Cassel, I'll try to explain a little:

Code: Select all
add_filter('ws_plugin__s2member_modification_email_sbj', 'my_s2_modification_sbj', 10, 2);
function my_s2_modification_sbj($s2member_default_sbj, $vars = array())
{
    return 'Thank you! Your account has been updated.';
}
 


ws_plugin__s2member_modification_email_sbj is a hook in the code that lets you hook to the script at that point to do other things to customize it. So with add_filter you're adding this customization using the function my_s2_modification_sbj where ws_plugin__s2member_modification_email_sbj is.

Now, my_s2_modification_sbj receives a couple of vars that are given by s2Member to that hook, so that all the data can be available to you for the customization. These are $s2member_default_sbj which is the default subject line, and $vars, which is an array with all the vars in the script where the hook is. These aren't copies of the variables, but a shortcut to the actual variables, so if you change one of their values in the customization, it'll be changed after the hook in the script.

It's inside this array $vars that you'll find the user's ID that Jason mentioned, as well as a lot of other info that you can use to customize the email. Here's an example using the user's ID in the customized subject line:

Code: Select all
add_filter('ws_plugin__s2member_modification_email_sbj', 'my_s2_modification_sbj', 10, 2);
function my_s2_modification_sbj($s2member_default_sbj, $vars = array())
{
    return 'Thank you user number ' . $vars['user_id'] . '! Your account has been updated.';
}
 


If you print_r, you'll get all the stuff in $vars so you see what's available to you. After you got the right array element names you need, remove the print_r. http://php.net/print_r

Code: Select all
add_filter('ws_plugin__s2member_modification_email_sbj', 'my_s2_modification_sbj', 10, 2);
function my_s2_modification_sbj($s2member_default_sbj, $vars = array())
{
    print_r($vars);
}
 


I hope this helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom thank you email per product?

Postby cassel » August 31st, 2011, 9:40 am

Getting there, slowly. More questions:

- with the print command, does it print on printer or on-screen? And how do i get to see those variables? how do i RUN that command on its own?

- should i look into using those hooks/filters ONLY for the existing users and let s2Member send the Thank you emails i set out in the dashboard already? or should the filter address both types of customers who purchased something?

- can i use similar conditionals in a filter as elsewhere i used conditionals?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Cristián Lávaque » August 31st, 2011, 9:11 pm

Yes, you can use PHP conditionals in your customizations with these hooks.

You can use this approach for the existing member upgrades and do the others from the user interface in WP Admin -> s2Member. But you can also use this approach on the ones that have the interface if you want to get advanced with conditionals in the emails, as you were asking to do before.

print_r would output to the web page you see in the screen, not your printer. Here's the documentation for it: http://php.net/print_r

I hope that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom thank you email per product?

Postby cassel » August 31st, 2011, 9:19 pm

Oh... i LOVE using conditionals. I am really getting the hang of it. Another quick question here: if i am using variables, maybe i don't even need to use conditionals? Say i determine that from ANY purchase, i will send a thank you note that will include the item name, that would do for any item purchased, right?

For example (i am working on it, so if i have errors, dont be surprised!)
Code: Select all
        return "Thank you FIRSTNAME \n\nYou have successfully purchased the " . $vars["item_name"] . "\n\nIf you haven't already done so, the next step is to Register a Username for the Campus.\n\n Please complete your registration here:" . wp_login_url ()\n\n
        "If you have any trouble, please feel free to contact us.\n\nOnce your registation is completed, you can login and access your bonuses here: http://scrapbookcampus.com/%%cv1%% ;


How do i replace the Custom Variable (cv1) in the URL to put it in the php? http://scrapbookcampus.com/%%cv1%%

And one last question on this for the night: would this php file override the standard from the dashboard?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Cristián Lávaque » September 1st, 2011, 2:00 am

You can just use the item's name, no need to use a conditional when there isn't a condition.

Where you can use a condition is in the product's URL, and instead of %%cv1%% check what the product is in $vars.

I think it'll override the template you have in your dashboard, but a test or Jason will confirm it. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 8:32 am

Where you can use a condition is in the product's URL, and instead of %%cv1%% check what the product is in $vars.

The problem being that the URLs are already set so if the $vars is different than the cv1 i created in the Paypal button and the URLs, it wont work.

(i still dont know HOW to see the $vars even with the print_r function: i have no clue what to run to see that)
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Jason Caldwell » September 1st, 2011, 11:43 am

Since this routine runs behind-the-scene, this is probably easier.
Code: Select all
add_filter('ws_plugin__s2member_modification_email_sbj', 'my_s2_modification_sbj', 10, 2);
function my_s2_modification_sbj($s2member_default_sbj, $vars = array())
{
    file_put_contents(WP_CONTENT_DIR."/debug.log", var_export($vars, true));
}
 
Run your test, and then open the /wp-content/debug.log file to see.

To answer your question, yes it's available. Use:
Code: Select all
$vars["cv"][1] 
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 12:32 pm

This is looking more and more promising (and understandable). Going to run that and come back with more questions (unless it works perfectly, in which case i will come and tell you so).
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 12:41 pm

Update:
I saved the file as s2-hacks.php in the mu-plugins directory;
Code: Select all
<?php
add_filter('ws_plugin__s2member_modification_email_sbj', 'my_s2_modification_sbj', 10, 2);
function my_s2_modification_sbj($s2member_default_sbj, $vars = array())
{   
    file_put_content(WP_CONTENT_DIR."/debug.log", var_export($vars, true));
}
?>

However, i cannot load the page itself to run a test purchase without getting this error message on top of the page:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/creas1/public_html/scrapbookcampus.com/wp-content/mu-plugins/s2-hacks.php:7) in /home/creas1/public_html/scrapbookcampus.com/wp-content/plugins/popup-domination/popup-domination.php on line 25


What did i do wrong?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Cristián Lávaque » September 1st, 2011, 1:01 pm

You seem to have an extra space after the ?>. You shouldn't have any empty space or lines outside the <?php ?> tags.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 3:03 pm

Thanks for the correction. Now, i ran a test transaction, and i cannot find a /wp-content/debug.log file Where did i mess up?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Jason Caldwell » September 1st, 2011, 3:24 pm

cassel wrote:Update:
Code: Select all
<?php
add_filter('ws_plugin__s2member_modification_email_sbj', 'my_s2_modification_sbj', 10, 2);
function my_s2_modification_sbj($s2member_default_sbj, $vars = array())
{   
    file_put_content(WP_CONTENT_DIR."/debug.log", var_export($vars, true));
}
?>
Please change this to file_put_contents, i.e. plural:
http://php.net/manual/en/function.file-put-contents.php
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 3:42 pm

This is not helping :(
I made the correction, uploaded it to the mu-plugins directory, ran a test transaction for a $1 made through a Paypal button. The transaction went through, a Paypal email was sent, but no Signup Confirmation email from my site, and still no debug.log file.
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Jason Caldwell » September 1st, 2011, 5:03 pm

Do you have log entries related to this transaction please?
Please see: /wp-content/plugins/s2member-logs/

If you don't have anything there, please enable s2Member's logging routines, in your Dashboard.
See: s2Member -> PayPal Options -> Account Details -> Logging.

If you continue to have trouble, please send us a screenshot of your s2Member -> PayPal Options -> Signup Confirmation Email configuration, and also post the full contents of the PHP file that you're modifying s2Member with ( i.e. your s2-hacks.php file ). Short of that, it sounds like you might need assistance from a PHP developer. The code samples above are really intended for a site owner with experience in PHP, and may not work for everyone.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 6:20 pm

With your usual patience, i will surely figure it out.

I do have a s2Member-logs and i can see the transaction AND the various variables (yayyyy!!!!). So, i code the hack file but i am getting still an error message. My guess is a syntax error. Here is the error i get on loading the page:

Parse error: syntax error, unexpected ';' in /home/creas1/public_html/scrapbookcampus.com/wp-content/mu-plugins/s2-hacks.php on line 5

and here is the code i created, in light of the variables i found in the paypal log:
Code: Select all
<?php
add_filter ("ws_plugin__s2member_modification_email_sbj", "my_s2_modification_sbj", 10, 2);
function my_s2_modification_sbj ($s2member_default_sbj, $vars = array ())
    {       
        return 'Thank you for purchasing '. $vars["item_name"] .;
    }
add_filter ("ws_plugin__s2member_modification_email_msg", "my_s2_modification_msg", 10, 2);
function my_s2_modification_msg ($s2member_default_msg, $vars = array ())
    {       
        return 'Thank you' $vars["first_name"] '\n\nYou have successfully purchased the ' $vars["item_name"] '\n\nIf you have not already done so, the next step is to Register a Username for the Campus.\n\n Please complete your registration here:' . wp_login_url ()'\n\n
        If you have any trouble, please feel free to contact us.\n\nOnce your registation is completed, you can login and access your bonuses here: http://scrapbookcampus.com/'$vars["cv"][1];   
    }
?>
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Jason Caldwell » September 1st, 2011, 8:46 pm

cassel wrote:
Code: Select all
<?php
add_filter ("ws_plugin__s2member_modification_email_sbj", "my_s2_modification_sbj", 10, 2);
function my_s2_modification_sbj ($s2member_default_sbj, $vars = array ())
    {       
        return 'Thank you for purchasing '. $vars["item_name"] .;
    }
add_filter ("ws_plugin__s2member_modification_email_msg", "my_s2_modification_msg", 10, 2);
function my_s2_modification_msg ($s2member_default_msg, $vars = array ())
    {       
        return 'Thank you' $vars["first_name"] '\n\nYou have successfully purchased the ' $vars["item_name"] '\n\nIf you have not already done so, the next step is to Register a Username for the Campus.\n\n Please complete your registration here:' . wp_login_url ()'\n\n
        If you have any trouble, please feel free to contact us.\n\nOnce your registation is completed, you can login and access your bonuses here: http://scrapbookcampus.com/'$vars["cv"][1];   
    }
?>

Try this instead at line #5:
Code: Select all
return 'Thank you for purchasing '. $vars["item_name"]; 


Also, this section has many syntax errors:
Code: Select all
        return 'Thank you' $vars["first_name"] '\n\nYou have successfully purchased the ' $vars["item_name"] '\n\nIf you have not already done so, the next step is to Register a Username for the Campus.\n\n Please complete your registration here:' . wp_login_url ()'\n\n
        If you have any trouble, please feel free to contact us.\n\nOnce your registation is completed, you can login and access your bonuses here: http://scrapbookcampus.com/'$vars["cv"][1];
Please have a look at these articles related to string concatenation.
http://phphowto.blogspot.com/2006/12/co ... rings.html
http://www.phpf1.com/tutorial/php-strin ... ation.html
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 9:09 pm

YESSSSSSSSSSSSSS! it works!!!
You are so patient with us (especially me!)

I got this as a confirmation email:
Subject: Congratulations! You officially registered for the Element Creation with PSP


Thanks Robert!

You have successfully purchased the Element Creation with PSP.

If you haven't already done so, the next step is to Register a Username
for the Campus.

Complete your registration here:
http://tinyurl.com/xxxxxxxx
If you have any trouble, please feel free to contact us.

Once your registation is completed, you can login and access your bonuses
here:
http://xxxxxxxxx
Enjoy your stay in the Campus,

Cassel
Scrapbook Campus


So, it does tell the registrant the right message, and the variable was in there to direct to the correct "success" page where the bonus for that SPECIFIC purchase will be posted (it is not yet, so dont try to grab anything!) However, at this point, i only have a curiosity question: is it expected to have the registration URL is using a tinyurl?

:?: :?: (had to edit the links because i found out someone used this post to access pages that should not be accessed by non-members)
Last edited by cassel on October 17th, 2011, 11:03 am, edited 1 time in total.
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Jason Caldwell » September 1st, 2011, 10:06 pm

Yes, the tinyURL is correct. The longer version is likely to get mangled by email applications, so we use a tinyURL inside email messages to prevent this. Nice work!
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Custom thank you email per product?

Postby cassel » September 1st, 2011, 10:12 pm

Nice TEAM work! If you want to refer to this thread for anyone else looking to customize their Signup confirmation, do not hesitate to send them to this thread (at least the end of it!) because it DOES work! And it adds another level of flexibility!
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Cristián Lávaque » September 1st, 2011, 11:52 pm

Great! Well done! :)

I already have pointed someone to this thread, but all of it because the explanations help understand the hack better.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Custom thank you email per product?

Postby cassel » September 17th, 2011, 5:03 pm

I am unsure what happened but today, one registrant sent me an email because she could not access what she had just purchased. I found out that the transaction went through, but didn't seem to "register" though s2M and her access was NOT automatically set up, so i did it manually. In the email she sent me, she was forwarding me the Thank you email she got and i noticed that the custom link that WAS apparently working in the posts above did NOT have the correct link, as it had only the beginning of the link and NOT the custom addition to it.

Curious about that, i email another registrant who completed the purchase yesterday and asked her for a copy of her thank you email and sure enough, that link is also incomplete. I dont really want to ask every registrant to email me their thank you email to check the exact time it broke so i sent a general email to all of them with the correct link.

But at this point, i am really stumped as i thought it was working fine since the test email did show the correct custom link and now, it does not. Any suggestion as where to look for the possible 'break'?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Custom thank you email per product?

Postby Jason Caldwell » September 20th, 2011, 7:13 pm

Thanks for the follow-up.
Can I see the code that you ended up with please?
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Custom thank you email per product?

Postby cassel » September 20th, 2011, 11:00 pm

I assume this is what you want to look at:
Code: Select all
<?php
add_filter ('ws_plugin__s2member_modification_email_sbj', 'my_s2_modification_sbj', 10, 2);
function my_s2_modification_sbj ($s2member_default_sbj, $vars = array ())
    {       
        return 'Thank you for purchasing '. $vars["item_name"];
    }
add_filter ('ws_plugin__s2member_modification_email_msg', 'my_s2_modification_msg', 10, 2);
function my_s2_modification_msg ($s2member_default_msg, $vars = array ())
    {       
        return "Thank you ". $vars["first_name"] . "\n\nYou have successfully purchased the " . $vars["item_name"] . "\n\nIf you have not already done so, the next step is to Register a Username for the Campus.\n\n Please complete your registration here:" . wp_login_url () . "\n\n
        If you have any trouble, please feel free to contact us.\n\nOnce your registation is completed, you can login and access your bonuses here: http://scrapbookcampus.com/".$vars["cv"][1];   
    }
?>


The strange thing is that it DID work in the test so i dont know what happened after.
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

PreviousNext

Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron