Some basic javascript help if possible!

Soldato
Joined
6 Nov 2004
Posts
5,778
Hi guy's I don't really know how to code I just look at a piece of code make changes and if it works then fine if not then I try again - probably not the best method but has worked thus far! Although i'll probably take the time to learn some day.

Anyways I use a wordpress plugin on my website to accept online food orders called wppizza. In the backend of wordpress there is page for the plugin that has an 'Order History Page' - basically orders get polled into there and it hasa dropdown menu option to change the status of the order.

So for example - when on status 'new' it is highlighted yellow and has a ringing noise (all orders when they arrive are on 'new' status by default). When changed to status 'acknowledged' it will print the order.

I have been given a code snippet by the developer so that when I change the order status it sends an email to the customer - I have edited the code to fit my needs however I am having one gripe. I would like to send an email when the status has been changed to 'delivered'. Currently it will send an email if it is changed to any status. I have done all the other parts and it works fine except for this one part but I can't figure out what he means by his instructions - what is the code needed for it to only send an email when 'delivered' is selected on the dropdown menu?

Here is the code snippet referencing that part:

Code:
/**************************************************************************************************
*
*	[admin order history: send email to customer on status change via ajax call]
*
**************************************************************************************************/
add_action( 'wppizza_ajax_action_admin', 'wpp7811_pizza_status_change_email');
function wpp7811_pizza_status_change_email($postdata) {
	if($postdata['vars']['type']=='statusupdate'){// could also add a " && in_array($postdata['vars']['type'],array('PROCESSED','REJECTED','REFUNDED'))" to only send when status changed to those
		$status=$postdata['vars']['status'];
I have included all the code before and one line of code after the part I need to amend. The line/lines I need to amend are

Code:
if($postdata['vars']['type']=='statusupdate'){// could also add a " && in_array($postdata['vars']['type'],array('PROCESSED','REJECTED','REFUNDED'))" to only send when status changed to those

The last part is the instruction but I don't understand what i'm meant to type here I have tried a few different ways and all produce errors when trying to visit my website.

Any help would be appreciated thanks.
 
Last edited:
Simple means like this
Code:
add_action( 'wppizza_ajax_action_admin', 'wpp7811_pizza_status_change_email');
function wpp7811_pizza_status_change_email($postdata) {
	if($postdata['vars']['type']=='statusupdate' && in_array($postdata['vars']['type'],array('DELIVERED')) )
		$status=$postdata['vars']['status'];
Assuning the status is DELIVERED.
 
This is what I originally tried however this does not send an email when the status has been changed although the website still works with this code.
 
add_action( 'wppizza_ajax_action_admin', 'wpp7811_pizza_status_change_email');
function wpp7811_pizza_status_change_email($postdata) {
if($postdata['vars']['type']=='statusupdate' && in_array($postdata['vars']['status'],array('DELIVERED'))"){
$status=$postdata['vars']['status'];
$to = $postdata['vars']['email'];/*who to send to*/
/**if only dealing with latin character domains/emails, else comment out**/
if(!filter_var($to , FILTER_VALIDATE_EMAIL)){
$txt=__("invalid email");/*alert if invalid email ->edit as required | EDITABLE| */
$txt.=PHP_EOL.$to;

print"".$to;
exit();
}

At the moment its looking in the wrong place for the update text.

The second file wont work, it works in the print order but completely breaks the website as they're both pulled from the same function.

Sorry I'm locked out of my email at the moment so I havent been able to send you the files.
 
Last edited:
It's ok mate I've managed to get both what I wanted doing working - the plugin developer finally decided to help me! Sorry to bother you with the request.
 
It's ok mate I've managed to get both what I wanted doing working - the plugin developer finally decided to help me! Sorry to bother you with the request.

It wasn't a bother at all mate. I'm really sorry to not have sent you the stuff earlier :(. It's been almost 13 days since I contacted Microsoft :(. I tried sending you a trust message with another email but I never got a reply so I assume you didn't get it.

Glad you've got it sorted though.

Can you show me how he resolved the 2nd bit though please. I couldn't get it working without breaking the website basket as they both seem to call from the same function.

Hope I haven't sullied future request for help :(.
 
Last edited:
This was the code used for the second part - can't take credit was the developer again! Hopefully I learn enough within the next few months to not need anyways help ha but I'm sure i'll still bother you if i'm stuck.

Code:
add_filter( 'wppizza_filter_print_order_single_item', 'myprefix_add_ingredients_items_linebreaks');
function myprefix_add_ingredients_items_linebreaks($item){
	$item['addinfo']=str_replace(', ','<br />',$item['addinfo']);	
return $item;
}
 
This was the code used for the second part - can't take credit was the developer again! Hopefully I learn enough within the next few months to not need anyways help ha but I'm sure i'll still bother you if i'm stuck.

Code:
add_filter( 'wppizza_filter_print_order_single_item', 'myprefix_add_ingredients_items_linebreaks');
function myprefix_add_ingredients_items_linebreaks($item){
	$item['addinfo']=str_replace(', ','<br />',$item['addinfo']);	
return $item;
}

It's so simple once you see it :(. I was changing the format directly in the wppizza plugin :(. In retrospect that's why it was changing the shopping cart page as well. How annoying right code but wrong place.

Please do. Was a nice change from Java and obj-c :D.

Again sorry for the email issues. Can you check your junk folder to see if my trust is in there if not I'll send it again.
 
Back
Top Bottom