after every order

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3439
    Olly
    Admin & Mod

    an action that runs after an order has been sent/paid for

    FOR WPPIZZA VERSION 3.x PLEASE REFER TO THIS DOCUMENT INSTEAD

     
     

    
    add_action( 'wppizza_on_order_executed', 'my_function',null, 2 );
    function my_function($orderId, $orderTable) {
    /*do your stuff*/
    }
    
    #4084
    Olly
    Admin & Mod

    so, as an example to send an sms to the customer after the order has been completed:
    (if you wanted to send a fax, or anything else for that matter, you can do something similar, depending and that particular api. the below should get you started though)

    
    !!!!OLD/LEGACY: USE THE EXAMPLE IN THE NEXT REPLY / FURTHER DOWN ON THIS PAGE!!!!
    
    add_action( 'wppizza_on_order_executed', 'my_sms_function',null, 2 );
    function my_sms_function($orderId, $orderTable) {
    	global $wpdb;
    	$getOrderDetails = $wpdb->get_row("SELECT customer_ini, customer_details ,order_ini, order_details FROM " .$wpdb->prefix . $orderTable . " WHERE id=".$orderId." ");
    	/*customer ini is a serialized array*/
    	$customerDetails=maybe_unserialize($getOrderDetails->customer_ini);
    	
    	/**if you just or additionally need all plaintext order and/or csutomer details as the appear in plaintext emails or need the whole array you can use any of the following*/
    	//$customerPlaintext=$getOrderDetails->customer_datails;/*customer data plaintext. might want to to a nl2br*/
    	//$orderPlaintext=$getOrderDetails->order_details;/*order data plaintext. might want to to a nl2br*/
    	//$customerDetailsArray=maybe_unserialize($getOrderDetails->customer_ini);/*customer data array*/
    	//$orderDetailsArray=maybe_unserialize($getOrderDetails->order_ini);/*order data array*/
    	// also available (amongst others but probebly the most useful):  order_date, transaction_id
    	
    	/**so, assuming you are using the "ctel" field for the customer telephone number. (if you are using a custom field it would be ccustom1, ccustom2 etc)*/
    	$customerTel=$customerDetails['ctel'];
    	
    	/**now implement however your sms gateway implements things to send things to that tel no**/
    	//->send your sms to $customerTel
    
    	return;
    }
    

    #7180
    Olly
    Admin & Mod

    as of v2.11.6 the following – somewhat less convoluted – could be used instead

    
    
    add_action( 'wppizza_on_order_executed', 'my_sms_email2fax_function');
    function my_sms_email2fax_function($orderId) {
    	
    	require(WPPIZZA_PATH.'classes/wppizza.order.details.inc.php');
    	$orderDetails=new WPPIZZA_ORDER_DETAILS();
    	$orderDetails->setOrderId($orderId);
    	$order=$orderDetails->getOrder();
    		
    		
    	/***********************************************
    		customer details
    	***********************************************/		
    	$customerDetails=$order['customer']['post'];//customer details
    	
    	
    	/***********************************************
    		other simplified variables to use if you want
    		if you want to build your own output
    	***********************************************/
    	//$siteDetails=$order['site'];//site specifics - probably only  useful in multisite setups
    	//$orderDetails=$order['ordervars'];//details of order (transaction id etc)
    	//$txt=$order['localization'];//localization variables
    	//$cartitems=$order['items'];//items in cart
    	//$orderSummary=$order['summary'];//summary of order
    
    	/***********************************************
    	example to get you going:			
    	if you were to un-comment the above
    	simplified variables, the below $email variable
    	would output the same details/html you will see
    	when clicking on "print" in the admin order history
    	next to an order
    	***********************************************/
    	//ob_start();
    	//require_once(WPPIZZA_PATH.'templates/wppizza-order-print.php');
    	//$email = ob_get_clean();
    
    		
    		
    	/************************************************
    	 [sms example - for this ignore the variables commented out above ]		
    	 assuming you are using the "ctel" field for the customer telephone number. 
    	 (if you are using a custom field for the customers tel no. it would be ccustom1, ccustom2 etc)
    	************************************************/
    	$customerTel=$customerDetails['ctel'];		
    		
    	/**now implement however your sms/email2fax gateway implements things to send things to that tel/fax no**/
    	//->send your sms to $customerTel		
    	//->send $email to email2fax gateway 
    	//-> etc
    
    return;
    }
    
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘after every order’ is closed to new replies.