Forum Replies Created
- AuthorPosts
-
Thanks Olly, that’s perfect all working now!
We’re looking forward to the rewrite sounds awesome, all the best!
Hi @smaj,
That may be the issue, the latest functions I’m using are below:
add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' ); function wpse8170_phpmailer_init( PHPMailer $phpmailer ) { $phpmailer->Host = 'mail.smtp2go.com'; $phpmailer->Port = '465'; // could be different $phpmailer->Username = '[email protected]'; // if required $phpmailer->Password = 'password'; // if required $phpmailer->SMTPAuth = true; // if required $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value $phpmailer->IsSMTP(); } function theme_enqueue_styles() { wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'avada-stylesheet' ) ); } add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function avada_lang_setup() { $lang = get_stylesheet_directory() . '/languages'; load_child_theme_textdomain( 'Avada', $lang ); } add_action( 'after_setup_theme', 'avada_lang_setup' ); // Save Order To TXT File // add_action( 'wppizza_on_order_execute', 'print_order', 1); function print_order($order_id, $order, $print_templates) { //declare new ORDER class and assign order details to var order $order = new WPPIZZA_ORDER(); $order = $order->session_formatted(); //check if delivery or pickup $pickup_delivery = ($order['ordervars']['order_type']['value_formatted'] == 'For Delivery' ? 1 : 2); //check if order has been paid $order_paid = ($order['ordervars']['payment_method']['value_formatted'] == 'Cash' ? 7 : 6); //add pickup_delivery and order_id to txt file $txt = "#Pizza*$pickup_delivery*$order_id*"; //$txt .= print_r($order, true); //add each item from order into txt file, including ONE extra option foreach($order['order']['items'] as $item) { $ititle = html_entity_decode($item['title']); $ititle = addslashes($ititle); $txt .= "$item[quantity];$ititle $item[price_label]"; foreach($item['extend_data']['addingredients']['multi']['1']['0'] as $key => $value) { //$txt .= print_r($value, true); $txt .= " + $value[count] $value[name]"; } $txt .= ";$item[pricetotal_formatted];"; } $txt .= "*{$order[summary][total][0][value_formatted]}*;{$order[customer][ccomments][value]};;{$order[customer][cname][value]};{$order['customer']['caddress']['value']};{$order[customer][ctel][value]};{$order['customer']['cemail']['value']};{$order[ordervars][order_date][value_formatted]};$order_paid;{$order[ordervars][payment_gateway][value]};;*#\r\n"; file_put_contents('/root/pathto/public_html/orders.txt', $txt, FILE_APPEND); } // Save Order To TXT File //
If you are getting no output follow back the variables through each step of the script.
$orderReason $orderTime $orderId
The printer connects to ordercallback.php
Hi @smaj,
I found the emails difficult to program, there are so many different components to sending the mail.
As Olly said, display errors. In your ordercallback.php file add:
error_reporting(E_ALL); ini_set('display_errors', 1);
The getorder.php file is redundant as far as I remember, I don’t believe its actually used for anything (unless your using the database rather than the text file).
Try printing every variable and step related to the mail in a text file or such.
Hi smaj, I’ve enabled the phpmailer in WordPress. It’s much more reliable!
I use SMTP 2 Go, which is free and quite good! Add this code and edit fields as required in your themes functions.php
add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' ); function wpse8170_phpmailer_init( PHPMailer $phpmailer ) { $phpmailer->Host = 'mail.smtp2go.com'; $phpmailer->Port = '465'; // could be different $phpmailer->Username = 'yourusername'; // if required $phpmailer->Password = 'yourpassword'; // if required $phpmailer->SMTPAuth = true; // if required $phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value $phpmailer->IsSMTP(); }
Thanks 🙂
Hi Smaj,
Disclaimer, I’m not the best PHP programmer if you could even call me that. So there are probably mistakes and better ways to code this. I’m aware of that. However it does the job for us!
Here’s the full ordercallback.php file, you’ll need to adjust the details in it.
<?php date_default_timezone_set('Australia/Brisbane'); //writed by GoodCom //author:coolbi //callback a=AC0001&o=10004&ak=Accepted&m=OK&dt=17:10&u=testuser&p=test include_once("getorder.php"); $sUserAgent=""; $useraccount=""; $userpwd=""; $resId=""; $orderId=""; $orderStatus=""; $orderReason=""; $orderTime=""; $defaultResId="AC001"; $defaultcount="testuser"; $defaultpwd="test"; if(isset($_SERVER["HTTP_USER-AGENT"])){ $sUserAgent=$_SERVER["HTTP_USER-AGENT"]; } if(isset($_GET['u'])){ $useraccount=strtolower($_GET['u']); } if(isset($_GET['p'])){ $userpwd=strtolower($_GET['p']); } if(isset($_GET['a'])){ $resId=$_GET['a']; } if(isset($_GET['o'])){ $orderId=$_GET['o']; } if(isset($_GET['ak'])){ $orderStatus=$_GET['ak']; } if(isset($_GET['m'])){ $orderReason=$_GET['m']; } if(isset($_GET['dt'])){ $orderTime=$_GET['dt']; } if(($useraccount==$defaultcount)&&($userpwd==$defaultpwd) && ($resId==$defaultResId)) { $ret=0; if($orderStatus=='Accepted'){ $ret=updateOrderstatus($orderId,'Delivered'); // Start Locate Email Address And Send // $ordid= "*" . $orderId . "*"; $line_no = 0; $fname = "orders.txt"; $lines = file($fname); foreach($lines as $line) { $line_no++; if(strstr($line, $ordid)) { preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $line, $matches); $orderTime = date('h:i a', strtotime($orderTime)); // Start Send Email // //Mail the message $to = $matches[0][0]; $subject = "Order Accepted - Delivery Time: " . $orderTime . " Your Restaurant"; $message = " <html> <head> <title>Thank you for your order!</title> </head> <body style='margin: 0px; background-color: #FFFFFF; font-size: 14px; color: #444444; font-family: Verdana, Helvetica, Arial, sans-serif;'> <table style='border-collapse:collapse;margin:10px 0; width:100%;'> <tr> <td> <center> <table style='border-collapse:collapse;width: 500px; margin: 0 auto; border: 1px dotted #CECECE; background: #F4F3F4;'> <tbody> <tr> <td> <table id='site' style='width:100%;padding: 30px; text-align: center; background-color: #21759B; color: #FFFFFF;'> <tbody> <tr><td style='text-align: center;font-size: 160%; font-weight: 600;'>Your Restaurant</td></tr> </tbody> </table> <table id='ordervars' style='width:100%;margin: 5px 0 30px 0; border-bottom: 1px dotted #cecece;'> <tr><td colspan='2' style='text-align: center;'>Your Order Has Been Confirmed.</td></tr> <tr><td style='width: 50%; white-space:nowrap; text-align: right; padding:2px;'>Order ID:</td> <td style='padding: 2px; word-break: break-word;'>" . $orderId . "</td></tr> <tr><td style='width: 50%; white-space:nowrap; text-align: right; padding:2px;'>Estimated Delivery Time:</td><td style='padding: 2px; word-break: break-word;'>" . $orderTime. "</td></tr> <tr><td colspan='2' style='text-align: center; padding:2px;'>Thank you for choosing Your Restaurant</td></tr> </table> </td> </tr> </tbody> </table> </center> </td> </tr> </table> </body> </html> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: Your Restaurant <[email protected]>' . "\r\n"; mail($to,$subject,$message,$headers); // WP MAIL define('WP_USE_THEMES', false); require_once('wp-load.php'); wp_mail($to,$subject,$message,$headers); /*if( !$phpmailer->send() ) { $txt = $phpmailer->ErrorInfo; file_put_contents('orders.txt', $txt, FILE_APPEND); } else { $txt = "Message sent!"; file_put_contents('orders.txt', $txt, FILE_APPEND); }*/ // End Send Email // }; // Start Delete Order Line Once Accepted // $ordid= "*" . $orderId . "*"; $line_no = 0; $fname = "orders.txt"; $lines = file($fname); foreach($lines as $line) { $line_no++; if(!strstr($line, $ordid)) $out .= $line; } $f = fopen($fname, "w"); fwrite($f, $out); fclose($f); // End Delete Order Line Once Accepted // } // End Locate Email Address And Send // } else if($orderStatus=='Rejected'){ $ret=updateOrderstatus($orderId,'Cancel:'.$orderReason); // Start Locate Email Address And Send // $ordid= "*" . $orderId . "*"; $line_no = 0; $fname = "orders.txt"; $lines = file($fname); foreach($lines as $line) { $line_no++; if(strstr($line, $ordid)) { preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $line, $matches); // Start Send Email // //Mail the message $to = $matches[0][0]; $subject = "Order Rejected - Your Restaurant"; $message = " <html> <head> <title>Order Rejected</title> </head> <body style='margin: 0px; background-color: #FFFFFF; font-size: 14px; color: #444444; font-family: Verdana, Helvetica, Arial, sans-serif;'> <table style='border-collapse:collapse;margin:10px 0; width:100%;'> <tr> <td> <center> <table style='border-collapse:collapse;width: 500px; margin: 0 auto; border: 1px dotted #CECECE; background: #F4F3F4;'> <tbody> <tr> <td> <table id='site' style='width:100%;padding: 30px; text-align: center; background-color: #21759B; color: #FFFFFF;'> <tbody> <tr><td style='text-align: center;font-size: 160%; font-weight: 600;'>Your Restaurant</td></tr> </tbody> </table> <table id='ordervars' style='width:100%;margin: 5px 0 30px 0; border-bottom: 1px dotted #cecece;'> <tr><td colspan='2' style='text-align: center;'>Your Order Has Been Rejected.</td></tr> <tr><td colspan='2' style='text-align: center; padding:2px;'>We apologise for the inconvenience unfortunately we are unable to fulfill your order" . $orderReason . "</td></tr> </table> </td> </tr> </tbody> </table> </center> </td> </tr> </table> </body> </html> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: Your Restaurant <[email protected]>' . "\r\n"; mail($to,$subject,$message,$headers); // WP MAIL define('WP_USE_THEMES', false); require_once('wp-load.php'); wp_mail($to,$subject,$message,$headers); /*if( !$phpmailer->send() ) { $txt = $phpmailer->ErrorInfo; file_put_contents('orders.txt', $txt, FILE_APPEND); } else { $txt = "Message sent!"; file_put_contents('orders.txt', $txt, FILE_APPEND); }*/ // End Send Email // }; // Start Delete Order Line Once Accepted // $ordid= "*" . $orderId . "*"; $line_no = 0; $fname = "orders.txt"; $lines = file($fname); foreach($lines as $line) { $line_no++; if(!strstr($line, $ordid)) $out .= $line; } $f = fopen($fname, "w"); fwrite($f, $out); fclose($f); // End Delete Order Line Once Accepted // } // End Locate Email Address And Send // } if($ret==1){ $ret=0; $ret=checkNewOrder(); header("HTTP/1.1 206 Partial Content"); if($ret!=0){ header("More-orders: 1"); } echo $ret; } } else{ print substr("",0,1); } ?>
My apologies, of course it’s staring me right in the face!
Not even for one million dollars? Hahaha 😉 I’ve read the link, I believe it may be useful to a large number of users and you would be able to resell as an add on?
Yes I know lol a bit of a contradiction. You have changed my mind since talking with you. I find it hard to say no to clients!
Much of the spam we get, we’ve never even dealt with the company before! If it’s from a company we’ve used before I don’t mind so much.
Thanks Olly 🙂
I hope so haha. We get hundreds of spam emails each day it’s too much -.-
Very true.
Quick question for you, has the comments variable in the array changed it’s name? Is it still ccomments?
$order[customer][ccomments][value]
Good guess! I will pass that on to him thank you. It might save me the hassle haha.
I personally get bombarded ALL the time, the SMS marketing has gone crazy in Australia.
That’s a fair idea, I don’t blame you!
It’s a little more relaxed over here in Australia, however yes still very much considered spam.
Unfortunately it’s a case of keep the boss happy or he’ll find someone else who will :\
Haha don’t shoot the messenger. I don’t get paid to argue with the boss.
The restaurant wishes to enable guest checkouts to increase conversion rates whilst maintaining the ability to Remarket email and SMS promotions in the future.
Thanks anyway, I suppose I’ll create a function for this.
Unfortunately we have guest checkout enabled and the majority of customers don’t register.
Is there a table in WP Pizza that stores the first name, last name, phone and email?
Perfect thanks again!
Thanks Olly, that’s exactly what I’m looking for!
That’s perfect thanks Olly!
Thanks Olly! I’ll update our code thank you.
While I’ve got you, is there a simple way to add a magnify type hover action to the menu items?
@Olly Hi Olly,
Please disregard the first issue, it appears to be fixed. Thank you for looking at it!
However I’m really struggling to loop through the extra ingredients I’m not familiar with recursive arrays.
[order][items][1.3.606.3.2.1|235ea5901ba3ea02a7d748b9b98b644e][extend_data][addingredients][multi][1][0][47]
Code so far:
// Save Order To TXT File // // Save Order To TXT File // add_action( 'wppizza_on_order_execute', 'print_order', 1); function print_order($order_id, $order, $print_templates) { //declare new ORDER class and assign order details to var order $order = new WPPIZZA_ORDER(); $order = $order->session_formatted(); //check if delivery or pickup $pickup_delivery = ($order['ordervars']['order_type']['value_formatted'] == 'For Delivery' ? 1 : 2); //check if order has been paid $order_paid = ($order['ordervars']['payment_method']['value_formatted'] == 'Cash' ? 7 : 6); //add pickup_delivery and order_id to txt file $txt = "#Gourmet*$pickup_delivery*$order_id*"; //$txt .= print_r($order, true); //add each item from order into txt file, including ONE extra option foreach($order['order']['items'] as $item) { $txt .= "$item[quantity];$item[title]"; foreach($item['extend_data']['addingredients']['multi']['1']['0'] as $key => $value) { //$txt .= print_r($value, true); $txt .= " $value[count]x$value[name]"; } $txt .= ";$item[pricetotal_formatted];$item[price_label];"; } //add all other order details into txt file $txt .= "*{$order[summary][delivery_charges][0][label]}*{$order[summary][discount][0][value_formatted]};{$order[summary][total][0][value_formatted]};{$order[ordervars][wp_user_id][value_formatted]};{$order[customer][cname][value]};{$order['customer']['caddress']['value']};{$order[customer][ctel][value]};{$order[ordervars][order_date][value_formatted]};$order_paid;{$order[ordervars][payment_gateway][value]};{$order[customer][ccomments][value]}*{$order[customer][ccustom1][value]};{$order['customer']['cemail']['value']};#\r\n"; file_put_contents('/home2/seoexpe1/public_html/orders.txt', $txt, FILE_APPEND); } // Save Order To TXT File //
Outputs:
#Gourmet*1*30*1;Atlantic 1 x Bacon 1 x Ham;$ 34.00;Family 15";*Free Delivery*;$ 34.00;Registered User (#1);Justin;23 daisy road mountain;0400000000;April 8, 2018 5:14 am;7;COD;test*;[email protected];#
- AuthorPosts