sgreen0 Posted February 18, 2012 Share Posted February 18, 2012 I'm using Paypal Shopmaker for an online store. It is all in PHP. I'm not much of a programmer - especially not PHP. I'd like to change the contents of the confirmation email a customer is sent for one product only. Here is the original code that puts the text into the email: } else { // Send notification email directly ewpp_LoadEmail("ipn.txt"); I'd like to test the Item array for the special product and put different text into the email. This is what I thought of: } else { // Send notification email directly // Add check for Total Sondheim Package if ($ewpp_Item["ItemName"]=="Total Sondheim Seminar Package") { ewpp_LoadEmail("ipn_total_sondheim.txt"); } else { ewpp_LoadEmail("ipn.txt"); } Do you think that might work? Or this? foreach ($arrCart as $cartItem) { if ($cartItem["item_name"] == "Total Sondheim Seminar Package") { ewpp_LoadEmail("ipn_total_sondheim.txt"); } } else { ewpp_LoadEmail("ipn.txt"); } Any help you can offer would be greatly appreciated. Stephen Stephen Quote Link to comment https://forums.phpfreaks.com/topic/257248-evaluating-array/ Share on other sites More sharing options...
smerny Posted February 18, 2012 Share Posted February 18, 2012 if you want it to replace everything if it's one of the items in $arrCart... try this $tssp = false; foreach ($arrCart as $cartItem) { if ($cartItem["item_name"] == "Total Sondheim Seminar Package") { $tssp = true; break; } } if ($tssp){ ewpp_LoadEmail("ipn_total_sondheim.txt"); } else { ewpp_LoadEmail("ipn.txt"); } Quote Link to comment https://forums.phpfreaks.com/topic/257248-evaluating-array/#findComment-1318616 Share on other sites More sharing options...
sgreen0 Posted February 18, 2012 Author Share Posted February 18, 2012 Thanks for the suggestion! It looks good. However, you comment brought up an issue I hadn't dealt with - if there are more items in the cart that just the one I'm filtering for... It IS possible that a customer might buy something else along with this. Hmmm.... For now, I'm going to try the code you suggested, and keep thinking about the other issue. Any ideas? Thanks again. Stephen Quote Link to comment https://forums.phpfreaks.com/topic/257248-evaluating-array/#findComment-1318664 Share on other sites More sharing options...
smerny Posted February 19, 2012 Share Posted February 19, 2012 $tssp = false; foreach ($arrCart as $cartItem) { if ($cartItem["item_name"] == "Total Sondheim Seminar Package") { $tssp = true; break; } } if ($tssp){ ewpp_LoadEmail("ipn_total_sondheim.txt"); } ewpp_LoadEmail("ipn.txt"); ? hard to know what to do without knowing more about the context Quote Link to comment https://forums.phpfreaks.com/topic/257248-evaluating-array/#findComment-1318774 Share on other sites More sharing options...
sgreen0 Posted February 19, 2012 Author Share Posted February 19, 2012 No problem. I appreciate your help. These products don't fly off the shelves - especially the Total Sondheim Package that costs $75. I'll leave things as they are (with the code you suggested) and see how things go as customers buy... Thanks again. Stephen http://www.anmtstore.com Quote Link to comment https://forums.phpfreaks.com/topic/257248-evaluating-array/#findComment-1318787 Share on other sites More sharing options...
jcbones Posted February 19, 2012 Share Posted February 19, 2012 You could make it work dynamically, if you made a naming convention for your email txt files. I would suggest either the whole name of the item, or you could specify X number of characters, say 10. So, if you did 10 characters, then your package name: Total Sondheim Seminar Package would have an email file of: ipn_total_sond.txt If you need it longer, just specify, and adjust. Example <?php $tssp = array(); foreach ($arrCart as $cartItem) { $tssp[] = 'ipn_' . str_replace(' ','_',substr($cartItem['item_name'],0,10)) . '.txt'; //this is the text files name: ipn_theFirst10charactersOfTheName.txt } if (!empty($tssp)) { //if tssp is not empty. foreach($tssp as $file) { if(file_exists($file)) { //search the array to see if the files exist. $email = $file; //the first one it finds, set the email variable, and break the loop. break; } } } if(!empty($email)) { //if email variable is set and not empty. ewpp_LoadEmail($email); //load the file. } else { ewpp_LoadEmail("ipn.txt"); //else load the default. } Quote Link to comment https://forums.phpfreaks.com/topic/257248-evaluating-array/#findComment-1318799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.