Author: super_admin_v3x

Create your own sales report

Modify the sales report generated when clicking the export link in WPPizza -> Reports The sales report can be manipulated using a variety of filters/actions according to the examples below. Depending on your requirements, you might need to use one, more or all of them. 

Get only todays orders on order history page

Only display todays orders in WPPizza -> Orderhistory if you only ever want to get todays orders on admin order history page, something like this might work for you wppizza_filter_orders_query @param: str (the query string) @return: str example: add_filter(‘wppizza_filter_orders_query’, ‘myprefix_admin_orderhistory_query_filter’); function myprefix_admin_orderhistory_query_filter($query){ $today = date(‘Y-m-d’,current_time(‘timestamp’)); 

Email/Print Templates

Email / Print template functions – Requires WPPizza v3.9.3+

wppizza_template_parameters / wppizza_template_markup (functions)

query for a certain set of orders and return print or email template markup – according to template selected – for each order

example :

/*********************************************************
*	[get email or print template parameters]
*	@since 3.9.3
*	@param array of args
*		@args str ('print' or 'emails')
*		@args mixed
*		(if $type 'emails' you can use a specific id(int) or  use 'customer' or 'shop' as id value to get the template parameters for the respective recipient)
*		(if $type 'print' you can use a specific id(int) or  '' (empty string) to get the default print template set to be used for printing)
*	@return array
*********************************************************/
	$args = array(
		'type' => 'print',
		'id' => 0,
	);
	$param = wppizza_template_parameters($args);


/*********************************************************
*	[get orders - see https://docs.wp-pizza.com/developers/?section=function-wppizza_get_orders for query parameters ]
*	example here queries for one order by id
*********************************************************/
	/*
		get order formatted for a particular order id
	*/
	$args = array(
		'query'=>array(
			'order_id' => $oId ,//order id you are quering for
		),
		'format' =>array(
			'blog_options' => array('localization', 'blog_info', 'date_format', 'blog_options'),
			'sections' => true,// this should be set to true for passing on [sections] array to wppizza_template_markup args below
		)
	);
	$order = wppizza_get_orders($args);
	/*
		formatted order
		reset to get the only one there is which includes localization etc
		NOTE: if your wppizza_get_orders query might return more than one result 
		,you should NOT reset the array here but use a loop instead for the template markup
		below passing on the relevant $order and $template parameters 
	*/
	$order = reset($order['orders']);


/*********************************************************
*	[get template markup - markup for a specific order based on a selected email or print template]
*	SHOULD BE USED INSIDE A LOOP IF MORE THAN ONE RESULT
*	@since 3.9.3
*	@param array of args
*		@args array (order already formatted)
*		@args array template parameters as returned by wppizza_template_parameters
*		@args bool false to get only the content type selected in the template, true to get plaintext AND html
*	@return mixed (array|str)
*********************************************************/
	$args = array(
		'order' => $order, 
		'param' => $param, 
		'content_type' => false
	);
	$markup = wppizza_template_markup($args);

wppizza_skeleton_template_emails (function)

get *email* skeleton template (“WPPizza->Templates->eMails”) by id or shop/customer inserting content between header and footer, replacing what is normally used to display order details

example:

$id = 0; /* this could be a template id or you can use 'shop' or 'customer' to get the email template in use for email to shop or customer */
$content= 'my email content';/* string */
$markup = wppizza_skeleton_template_emails($id, $content);

/*
   $markup will now be the whole template as a string using 
   $content as the message between header and footer
*/

wppizza_skeleton_template_print (function)

get *print* skeleton template (“WPPizza->Templates->Print”) by id, inserting content between header and footer, replacing what is normally used to display order details

example:

$id = 0; /* print template id - int */
$content= 'my print content';/* string */
$markup = wppizza_skeleton_template_print($id, $content);

/*
   $markup will now be the whole template as a string using 
   $content as the message between header and footer
*/

On (admin) order 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) 

Customise order id

A filter to further ( or use instead) modify the order number than is possible in WPPizza->Order Settings->Global Note, this will NOT change the entry in the db. Only in emails and order history. if you change this filter at any time later , the 

Gateway filters frontend

Conditionally display gateways

if you wanted to disable a gateway conditionally (lets say no cash on delivery for non logged in users) you could add this to your themes functions.php

wppizza_filter_gateways_orderpage

@param: array
@return: array

example:

add_filter('wppizza_filter_gateways_orderpage', 'my_custom_gateways_filter');
function my_custom_gateways_filter($gateways){
	/* disable Cash on delivery for non-logged in users */
	if( !is_user_logged_in()){
		unset($gateways['COD']);//gateway keys are always uppercase
	}
return $gateways;
}

wppizza_filter_gateways_payment_options

as of wppizza 3.2.5 you can also do something like the following to conditionally enable/disable gateways depending on order value

add_filter('wppizza_filter_gateways_payment_options', 'my_custom_gateways_on_zero', 10 , 3);
function my_custom_gateways_on_zero($gateway_objects, $order_data,  $user_data){

	/*
		just for convenience
	*/
	$cart_total = $order_data['summary']['total'][0]['value'];
	
	/* 
		Example:
		if cart total is zero, disable all credit card payment gateways 
		i.e simply keep COD (which must be enabled for this to work of of course)
	*/
	if(empty($cart_total)){
		foreach($gateway_objects as $id => $obj){	
			
			/* hint: you could - temporarily - do a print_r($id) here to see all the id's associated with any gateways you have enabled */
			
			if($id !== 'COD'){
				unset($gateway_objects->$id);	
			}
		}
	}

	/* 
		Example:	
		if cart total is > zero, disable all NON credit card gateways - if that's what suits you
		you can use both examples in conjunctions with each other of course
	*/	
	if(!empty($cart_total)){
		unset( $gateway_objects->COD );
	}

	/* 
		Example:	
		if cart total is < 25, disable "Credit Card on Delivery" gateway
	*/
	if($cart_total < 25){
		unset($gateway_objects->CCOD);
	}

	/* 
		Note: If you want to conditionally do any of the above depending on if delivery or pickup was selected	
		simply add / wrap into another conditional like so
	*/
	if(!empty($order_data['checkout_parameters']['is_pickup'])){
		/* is pickup */ 
	}else{
		/* is delivery */
	}


return $gateway_objects;
}

For some globally available wppizza functions you could use in your conditionals above, refer to “Global WPPizza Functions”

Allow discounts for credit card payment gateways

By default you can only add dsicounts to COD type gateways as adding a discount to credit card gateways could result in the shop being charged more by the gateway provider than what it would earn with a sale. However, if you need to do this for whatever reason you could use the filter below (using Mollie here as an example gateway)

wppizza_filter_gateway_objects

@param: obj
@return: obj

example:

add_filter('wppizza_filter_gateway_objects', 'myprefix_filter_gateway_objects');
function myprefix_filter_gateway_objects($obj){
	/* 5 EUR/USD/whatever discount */
	$obj->MOLLIE->discounts['fixed'] = 5;
	/* and/or for 5 percent instead */
	$obj->MOLLIE->discounts['percent'] = 5;
return $obj;
}

Get (logged in) users previous order details

Gettings ome info about a logged in users previous orders programatically the ‘wp’ action hooks is only for demonstration purposes. you will probably want to use another action or filter hook as required /* change wp hook to whatever is appropriate */ add_action(‘wp’, ‘my_custom_loggedin_customer’); function 

Change prices of menu item(s) depending on day of week

Dynamically change menu items prices depending on weekday a filter to change menu items prices depending on day of week. To use in your theme’s functions.php using the wordpress standard get_post_metadata filter get_post_metadata (wordpress standard filter) @param: array @return: array example: /*** change “myprefix” occurences 

Prices output in loop

Dynamically change menu items prices display in loop

an example to add “from” in front of a particular menu item’s price

wppizza_filter_post_prices

@param: array
@param: obj
@param: str
@return: array

example:

add_filter('wppizza_filter_post_prices', 'myprefix_wppizza_item_prices', 10, 3);
function myprefix_wppizza_item_prices($prices, $post, $style) {
	/* add "from" before price of menu item with id 415, but only for first size (zero indexed) */ 
	if($post->ID == 415 ){/* wppizza menu item with id 415 */
		foreach($prices as $menu_size_key => $price){
			if($menu_size_key == 0){/* first size only */
				$prices[$menu_size_key]['price'] = __('from').' '.$prices[$menu_size_key]['price'];
			}
		}
	}

return $prices;
}

Additional validation function

Adding additional validation functions to fields in WPPizza -> Order form There are a number of additional javascript validation functions in-built into the plugin. However, aside from the default ones you can already select you have to selectively enable the ones that are of use