Developers

  1. Modify Css / Styles / Layout
    1. Frontend Css
    2. Admin Css
  2. Templates
    1. Pages
      1. page.order.php
      2. page.confirm-order.php
      3. page.processing.php
      4. page.thankyou.php
      5. page.cancelled.php
      6. page.purchase-history.php
    2. Order
      1. itemised.php
      2. summary.php
      3. transaction_details.php
    3. Global
      1. orderinfo.php (Widget)
      2. openingtimes.php (Widget)
      3. additives.php (Widget)
      4. navigation.list.php (Widget)
      5. navigation.dropdown.php (Widget)
      6. search.php (Widget)
      7. totals.php (Widget)
      8. pickup_choice.php (Mixed)
      9. login.php (Module)
      10. profile.register.php (Module)
      11. profile.update.php (Module)
      12. pages.pickup_note.php (Module)
      13. formfields.inputs.php (Module)
      14. formfields.values.php (Module)
    4. Cart
      1. cart.container.php
      2. cart.shopclosed.php
      3. cart.empty.php
      4. cart.pickup_note.php
      5. cart.checkout_button.php
      6. cart.empty_cart_button.php
      7. cart.minimum_order.php
      8. minicart.php
    5. Loop (Menu Items)
      1. header.php
      2. no_results.php
      3. posts.title.php
      4. posts.thumbnail.php
      5. posts.prices.php
      6. posts.content.php
      7. posts.permalink.php
      8. additives.php
      9. pagination.php
      10. theme-wrapper.php
    6. Search Results
      1. search.php
    7. Single Menu Item
      1. single.php
    8. functions.php
  3. Filters, Actions, Functions
    1. Global WPPizza functions
    2. WPPizza options (Filter)
    3. Currency (Filter)
    4. After every order (Action)
    5. Getting Orders (Function)
  4. Constants
    1. Admin Name
    2. Admin Menu Icon
    3. SORT_ITEMS_AS_ADDED
    4. SINGLE_PERMALINK_VAR
    5. WIDGET_CSS_CLASS
    6. PLAINTEXT_LINE_LENGTH
    7. ADMIN_{CONSTANTS}
    8. DEV_{CONSTANTS}
    9. INSTALL_{CONSTANTS}
    10. TRANSACTION_{CONSTANTS}
  5. Codesnippets
    1. Create your own sales report
    2. Order history - todays orders
    3. Add attachment to email
    4. On order status update
    5. Unconfirmed Orders
    6. Customise order id
    7. Changing post type arguments
    8. Gateway filter frontend
    9. Users previous orders
    10. Dynamic menu item prices
    11. Prices output loop
    12. Pickup Opening Times
    13. Additional validation function

5.4.Send email on (admin) status update

Sending an email whenever you change the status of an order in WPPizza -> Orderhistory

send an email (or whatever else it is you would like to do) when you change the status of an order in the order history

wppizza_on_orderstatus_change

@param: array (order details)
@param: str (the status the order has been changed to – something like ‘REFUNDED’, ‘NEW’, ‘ACKNOWLEDGED’ etc)
@param: array (wppizza options set of the blog/site where the order was made. In a multisite setup – if you are displaying all orders from all sites in the “master” site – this might be different to the current site you are on. For the current sites blogoptions use global $wppizza_options; and use those)
@param: str (plaintext template of a selected template id if using filter below)
@param: str (html template of a selected template id if using filter below and template set to be html – @since wppizza 3.5.1)
@return: str (js alert after change was completed – empty to omit alert)

example:

add_filter('wppizza_on_orderstatus_change', 'myprefix_on_orderstatus_change', 10, 5);
function myprefix_on_orderstatus_change($order_details, $order_status, $blog_options, $plaintext_template, $html_template){
	/*
	 if in a multiste environment use global $wppizza_options; 
	 to get wppizza options of the site you are in. else $blog_options will do if you need them 
	*/
	
	/*
	 get the customers address
	 from order_details array
	 var_dump($order_details) to get all details
	*/
	$to_address = $order_details['customer']['cemail']['value'];


	/**if only dealing with latin character domains/emails do a quick validation,  else comment out**/
	if(!filter_var($to_address , FILTER_VALIDATE_EMAIL)){
		$js_alert = __('invalid email');/*alert if invalid email  | EDIT AS REQUIRED  */
		$js_alert .= PHP_EOL . $to_address;
	return $js_alert;
	}

	/*
		subject line
	*/
	$subject = 'The Subject';/* subject line  | EDIT AS REQUIRED */
	/*
		email body / message
	*/
	$message = __('hello');/*message | EDIT AS REQUIRED*/
	/* add plaintext email template of order underneath if exists - see filter below how to get this | EDIT AS REQUIRED */
	$message.= !empty($plaintext_template) ? PHP_EOL . $plaintext_template .PHP_EOL  : '' ;


	/*
		headers
	*/
	$headers   = array();
	$headers[] = "MIME-Version: 1.0";
	$headers[] = "Content-type: text/plain; charset=utf-8";
	$headers[] = "From: Sender Name <[email protected]>";/**who it's from | EDIT AS REQUIRED**/
	$headers[] = "X-Mailer: PHP/".phpversion();

	/*
		send the email, wrap message at 74 chars for maximum email client compatibility
	*/
	$mailSent = mail($to_address, $subject, wordwrap($message, 74, "\r\n"), implode("\r\n", $headers));

	/*
		set js alert after sending
	*/
	if($mailSent){
		$js_alert = __('Email sent to '.$to_address.''.PHP_EOL.'Status: '.$order_status.'');/*alert on successful sending | EDIT AS REQUIRED*/
	}else{
		$js_alert = __('Error sending email to '.$to_address.''); /*alert on error sending | EDIT AS REQUIRED*/
	}

return $js_alert;
}

wppizza_on_orderstatus_change_add_template

if you would like the markup of an email template as set in WPPizza->Templates->Emails available in your above filter as the 4th parameter, use the below filter example to select from one of the the id’s . If the template is set to be HTML the 5th parameter will contain the html markup.

@param: int (emails template id’s . default = false)
@return: int|false (selected email template id or false)

example:

add_filter('wppizza_on_orderstatus_change_add_template', 'myprefix_on_orderstatus_change_add_template');
function myprefix_on_orderstatus_change_add_template($selected_email_template_id){
	/* get plaintext email from template with id 1 for this order */
	$selected_email_template_id = 1;	
return $selected_email_template_id;
}

Add some javascript to order history to execute if order status changes

wppizza_filter_orderhistory_markup

@param: array (array of markup parts)
@return: array

add_filter('wppizza_filter_orderhistory_markup', 'my_custom_orderhistory_markup');
function my_custom_orderhistory_markup($markup){
	
	/*	
	add javascript to the end of the markup
	*/
	$markup['my_js_markup']= "<script type='text/javascript'>
        /* <![CDATA[ */
        jQuery(document).ready(function($){
        $(document).on('change', '.wppizza-orderhistory-order-status', function(e){
            var self=$(this);           
            var selId=self.attr('id').split('-').pop(-1);
            var selfVal=self.val();
			/* do things when you change the status to PROCESSED, in this case trigger the print button **/
            if(selfVal=='PROCESSED'){
                    var triggerTarget=$('#wppizza-orderhistory-print-order-'+selId+'');
                    triggerTarget.trigger('click');
            }
        });
        });
        /* ]]> */
    </script>";

return $markup;
}

Add some javascript to order history to execute if order status changes to “PROCESSED” and execute an ajax call passing on some js prompt

example:

add_filter('wppizza_filter_orderhistory_markup', 'my_custom_orderhistory_markup');
function my_custom_orderhistory_markup($markup){
	
	/*	
	add javascript to the end of the markup
	*/
	$markup['my_js_markup']= "<script type='text/javascript'>
        /* <![CDATA[ */
        jQuery(document).ready(function($){
        $(document).on('change', '.wppizza-orderhistory-order-status', function(e){
            var self=$(this);           
            var selId=self.attr('id').split('-').pop(-1);
            var selfVal=self.val();
            
            var order=selId.split('_');
            var blog_id=order[0];
            var order_id=order[1];
            
            
	/* do things when you change the status to PROCESSED - in this case adding a prompt and passing this on to an ajax call **/
        if(selfVal=='PROCESSED'){

         	var message = prompt('your message', 'default message');

				jQuery.post(ajaxurl , {action :'myprefix_admin_ajax',vars:{'type':'statusupdate', 'blog_id':blog_id, 'order_id':order_id, 'message':message}}, function(response) {
						alert('ok');
				},'text').error(function(jqXHR, textStatus, errorThrown) {alert('error : ' + errorThrown);});
            }
        });
        });
        /* ]]> */
    </script>";

return $markup;
}

/**
	admin ajax
**/
add_action('wp_ajax_myprefix_admin_ajax', 'myprefix_set_admin_ajax' );
function myprefix_set_admin_ajax(){
	// listen to type statusupdate being posted 	
	if($_POST['vars']['type'] == 'statusupdate'){
		
		/* blogid (if required) */
		$blog_id = (int)$_POST['vars']['blog_id'];// sanitise blog_id , just for good measure
		
		/* order */
		$order_id = (int)$_POST['vars']['order_id'];// sanitise order id , just for good measure
		$order = wppizza_get_completed_order($order_id);// get order details
		
		/* prompt message set  - you probably want to validate/sanitize this somewhat*/
		$message = $_POST['vars']['message'];
		
		/* 
		send email for example (as outlined above) or whetever you need to do 
		utisiling the variables you have available if needs be (like $order, $message) such as		

		 to get the customers address from order array ( var_dump($order) to get all order details)
		*/
		$to_address = $order['customer']['cemail']['value'];		
		
	}
die();//important
}
Yes No Suggest edit
Suggest Edit

documentor id 5