if you want to develop you own script/plugin etc based on any wppizza orders, please refer to the documentation below
Note: Result sets will always be sorted by order date in descending order
@ since 3.5
@ param array
@ return array
Note: compared to the now removed get_orders_completed() all dimensions of the returned array are arrays themselves now. no more mix ‘n’ match between arrays and objects
The following values will be used when not setting ANY arguments (which is essentially the default before any dropdown options might be selected in WPPizza -> Order History)
$args = array( 'query' => array( 'wp_user_id' => false , 'email' => false , 'order_id' => false , 'hash' => false , 'payment_status' => array('COMPLETED', 'UNCONFIRMED', 'REFUNDED', 'REJECTED') , 'order_status' => false , 'custom_status' => false , 'blogs' => {default depends on options set and if it's a multisite setup. see notes below}, 'summary' => false , ), 'pagination' => array( 'paged' => 0 , 'limit' => {default depends on options set. see notes below}, ), 'format' => true , ) //run query, and get results $orders = wppizza_get_orders($args); //this would be the same as simply using $orders = wppizza_get_orders();
query the wppizza orders table according set parameters
int
false
str|array
false
int
false
str
false
str|array
array('COD', 'COMPLETED', 'UNCONFIRMED', 'REFUNDED', 'REJECTED')
'COD', 'COMPLETED', 'UNCONFIRMED', 'CAPTURED', 'REFUNDED', 'REJECTED', 'INPROGRESS', 'INITIALIZED', 'AUTHORIZED', 'CANCELLED', 'PAYMENT_PENDING', 'FAILED'
mixed (false|str|array)
false
'NEW','ACKNOWLEDGED','ON_HOLD','PROCESSED','DELIVERED','REJECTED','REFUNDED','OTHER','CUSTOM_1','CUSTOM_2','CUSTOM_3','CUSTOM_4'
mixed (false|str|array)
not set
timestamp (integer)
not set
timestamp (integer)
none
mixed (bool|array)
bool (see notes below)
bool
false
query an order for a specific meta key/value
see bottom of this page how to add meta values to an order
array of column/value arrays
void
limit results set of the query – ignored if ‘summary’ => true or only querying for a specific ‘order_id’ or ‘hash’ for a single blog only (as it will only ever return one result at most)
int
0
int
[int]
– as per option set in “WPPizza->Settings->Order History : Max Results”format the output for each order defaults to true. Set to false for unformatted order results – ignored if $args[‘query’][‘summary’] is set
bool
false
bool
false
Get completed orders for a user with user id 23 (use 0 to query orders from guest/non-registered customers) from the current blog only, limited to first 5 results with output being formatted
Query:
$args = array( 'query'=>array( 'wp_user_id' => 23 ,//user id 'payment_status' => 'COMPLETED',//completed only 'blogs' => false ,//current blog only ), //order values returned for the first 5 orders found (always by descending date) 'pagination' =>array( 'paged' => 0 , 'limit' => 5 , ), //formatting omitted, defaults to true ); $orders = wppizza_get_orders($args);
Results [Array]:
[total_number_of_orders] => 194 // [int] total number of orders found without pagination limit [total_value_of_orders] => 14265.59 //[float] total value of orders found without pagination limit [gateways_idents] => Array // [array] of all gateways used in results set ( [COD] => COD ) [number_orders_on_page] => 5 //[int] total number of orders within pagination limit [value_orders_on_page] => 269.17 //[float] total value of orders within pagination limits /* array of order values for each order returned withing pagination limits the key for each order is always made up of [blog_id]_[order_id] but you can also get the blog id in [site][blog_id][value] and the order id in [ordervars][order_id][value] */ [orders] => Array ( [1_623] => Array ( [site] => Array ( /*.... site data for this order ....*/ ) [ordervars] => Array ( /*.... general ordervars data for this order....*/ ) [customer] => Array ( /*.... customer data for this order....*/ ) [order] => Array ( /*.... cart items ....*/ ) [summary] => Array ( /*.... summary of order ()....*/ ) ) [1_622] => Array ( /* second order results set */ ) /* more order results */ )
Get completed or confirmed orders with an order status of ‘NEW’ and ‘meta_key’ equals ‘mymetakey’ and ‘meta_value’ equals ‘mymetavalue’. ()
Query:
$args = array( 'query'=>array( 'payment_status' => array('CONFIRMED', 'COMPLETED'),//completed only 'order_status' => 'NEW',//get orders with status NEW only ), 'meta'=>array( 'query' => array( //if you do not want to restrict by meta_key, omit array( 'column' => 'meta_key', 'value' => 'mymetakey', ), //if you do not want to restrict by meta_value, omit array( 'column' => 'meta_value', 'value' => 'mymetavalue', ), ), ), ); $orders = wppizza_get_orders($args);
Results set returned will be as above, restricted to all orders that match the meta query as well
Get completed orders of all users (including non-registered/guests) from all blogs, limited to first x results as set in “WPPizza->Settings->Order History : Max Results” with output being formatted and added class idents
Query:
global $wppizza_options; $args = array( 'query'=>array( 'payment_status' => 'COMPLETED', 'blogs' => true,//will be ignored if not in a multisite setup or simply omit entirely ), 'pagination' =>array( 'paged' => 0 , 'limit' => $wppizza_options['settings']['admin_order_history_max_results'] , ), 'format' => array( 'class_idents' => true, ), ); $orders = wppizza_get_orders($args);
Results [Array]:
/* as above example, but with class-indent added to each order parameter you could use in any outputs for consistent class names (perhaps adding a distinct prefix to each class name as well) so the order date would now return somthing like this */ [orders] => Array ( [1_623] => Array ( ............ [ordervars] => Array ( [order_date] => Array ( [label] => Order Date : [value] => 2018-05-15 00:48:08 [value_formatted] => May 15, 2018 12:48 am [class_ident] => order-date //this parameter is now added to each one ) ............ ) ............ ) [1_623] => Array ( /* second order */ ) ///etc )
Simply check if there are any new orders, without returning each orders values
Query:
$args = array( 'query'=>array( 'payment_status' => 'COMPLETED',//get completed orders only 'order_status' => 'NEW',//get orders with status NEW only 'summary' => true,// only return count/totals ), ); $orders = wppizza_get_orders($args);
Results [Array]:
[total_number_of_orders] => 194 // [int] total number of orders found without pagination limit [total_value_of_orders] => 14265.59 //[float] total value of orders found without pagination limit /* no other parameters will get returned */
If you are outputting the order results somehow/somewhere you could use the below helper to add pagination
@ param [int] : should be the total number of orders returned by order query before limit @ param [int] : should equal the limit set in the orders query pagination['limit'] parameter @ param [int] (default:false if omitted) : if set to an integer (2 for example) will display a max of 2 pagination links either side of current page, and use '...' where appropriate. false to show all links @ param bool (default:true if omitted) : true to display some pagination info underneath button , false to omit @ param false|int (default:false if omitted): links to current page. set a distinct post id to link to the page with this id (might be required for ajax requests) @ return str $pagination = wppizza_orders_pagination($total_no_of_orders, $limit, $ellipsis, $pagination_info, $post_id); print $pagination;
Adding Meta Data to an Order
/* adding 'mymetakey' with a value of 'mymetavalue' to an order, *when an order gets submitted* if mymetavalue is not a string/integer it will be serialized */ add_action('wppizza_add_order_meta', 'myprefix_add_order_meta', 10, 2) /*------------------------------------------------------------------------------ # $param order id # $param order values # $returns int (meta_id added) ------------------------------------------------------------------------------*/ function myprefix_add_order_meta($order_id, $order){ $meta_id = wppizza_do_order_meta($order_id, 'mymetakey', 'mymetavalue'); return $meta_id; }
/* adding 'mymetakey' with a value of 'mymetavalue' to an order, *even BEFORE an order gets submitted - i.e as soon as the user arrives on your orderpage * if mymetavalue is not a string/integer it will be serialized Note: if you also use 'wppizza_add_order_meta' with the same metakey, 'wppizza_add_order_meta' will overwrite the value captured with 'wppizza_add_order_meta_init' (as it happens after) */ add_action('wppizza_add_order_meta_init', 'myprefix_add_order_meta_init', 10, 1) /*------------------------------------------------------------------------------ # $param order id # $returns int (meta_id added) ------------------------------------------------------------------------------*/ function myprefix_add_order_meta_init($order_id){ $meta_id = wppizza_do_order_meta($order_id, 'mymetakey', 'mymetavalue'); return $meta_id; }
Updating Meta Data for an Order
/* updating metavalues for a specific meta_key relating to a specific order if it the meta_key for this order does not exist yet, it will be added, else the value will be updated if $meta_value is not a string/integer it will be serialized */ /*------------------------------------------------------------------------------ # $param int - order id we are updating # $param str - meta key we are updating # $param mixed - value to update/insert # $returns int (meta_id added/updated) ------------------------------------------------------------------------------*/ $order_id = 123; $meta_key = 'mymetakey'; $meta_value = array( 'key1'=> 'a', 'key2'=> 'b'} /* or $meta_value = 'new value'; if you want */ $meta_id = wppizza_do_order_meta($order_id, $meta_key, $meta_value);
Deleting a specific metakey of Order
/*------------------------------------------------------------------------------ # $param int - order id # $param str - meta key we are deleting of this order # $returns bool ------------------------------------------------------------------------------*/ $order_id = 123; $meta_key = 'mymetakey'; $meta_id = wppizza_delete_order_meta($order_id, $meta_key');
Get metavalue of an Order for a specific metakey
/*------------------------------------------------------------------------------ # $param int - order id # $param str - meta key we are querying # $param bool - return value only # $returns mixed ------------------------------------------------------------------------------*/ $order_id = 123; $meta_name = 'mymetakey'; $meta_value_only = true; $res = wppizza_get_order_meta($order_id, $meta_name, $meta_value_only );
Deleting an order and its associated meta data by id/blogid
/*------------------------------------------------------------------------------ # $param int - order id # $param int - blog id (only relevant in mutisite setups). set blog id to distinctly target order of a specific blog, or false/omit for current blog # return void ------------------------------------------------------------------------------*/ /* multisite setups: */ $order_id = 123; $blog_id = 1; wppizza_delete_order($order_id, $blog_id); /* single site setup, simply do: */ $order_id = 123; wppizza_delete_order($order_id);
This is it for the time being, but if you have a particular query you need like help with and you cannot figure out , let me know and I’ll see what I can do
]]>If you want to do any kind of wordpress development other than “point and click” or basics like css etc it is imperative to know how wordpress actions and filters work.
Actions/Filters let extend or change functionality of plugins/themes (or wordpress itself for that matter) without having to touch core files and therefore loosing the ability to ever update anything again or having to re-apply your changes every time a plugin or theme gets updated. (In fact editing core files is just generally a bad idea in any case)
If you do not know about wordpress actions and filters, I would recommend you use your favourite search engine and look for some tutorials (there are plenty of them available) to familiarise yourself with that concept. I promise you, once you understand how these work, a whole new world of wordpress development will open up for you.
A very very basic summary:
that’s it on that front for the time being….
This section aims to document the most important wppizza functions, actions and filters and will expand over time depending on user requests and general usefulness.
If you are missing anything in particular – or indeed have been customising WPPizza v2x and now wish to transfer your cutomisations to wppizza v3.x but cannot find an answer in the documentation here – contact me using the usual channels.
I will – hopefully – be able to point you in the right direction.
However, please note that some filters and actions have changed completely or have even been removed in favour of other ways to do things (like additional shortcode attributes). Furthermore, a few things have been removed entirely in wppizza v3x (mostly for consistency reasons) in favour of alternatives.
Anyway, get in touch and we’ll see what we can do.
Typically – according to the wordpress codex – you would put you alterations into your themes or child themes functions.php as outlined above. However, if you do that you will always have to re-apply said alterations if you decide to switch themes for one reason or another.
Unless your changes are very specific to a particular theme, a far better alternative (as far as I am concerned anyway) would be to create a dedicated WPPizza Custom plugin (or whatever you want to call it) and add all your filterings, actions etc there instead.
The advantage of it being that it is irrelevant what theme you might have enabled and – even more so if you are in a multisite setup with different themes for each subsite – you can simply enable this plugin without having to worry about having to apply your coding to each theme (or subsite if using different themes in a multisite setup – simply network enable the plugin).
To do so, create a file (let’s name it wppizza-customisation.php for example) and add the following to the top of the file:
<?php
/*
Plugin Name: WPPizza Custom Functions
Description: WPPizza custom functions that run regardless of theme used (use instead of putting them into a theme's functions.php)
Version: 0.1
Author: ollybach
Author URI: https://www.wp-pizza.com
*/
/*
add your filters/actions etc here
*/
Add your filters, actions and whatever else you need to do to that file, save and copy this file to your [Wordpress-Install-Path]/wp-content/plugins/
directory (or if you wish into a subdirectory called wppizza-custom or whatever else you want to call it).
Then simply go to your plugins page in your wordpress installation and activate.
Your WPPizza customisations will now be completely independent of any themes or child themes that may or may not be in use.
Furthermore, if you need to do the same things on another WPPizza site you could simply copy this file there and activate the plugin.
Maybe the above is of some use to someone.
]]>there are several filters you can use to change the WPPizza custom post type as well as taxonomies labels, arguments. Please refer to WordPress codex regarding register_posttype and register_taxonomy.
filter wppizza custom post type lables
@param: array (labels of custom post type)
@return: array
example:
add_filter('wppizza_filter_cpt_lbls', 'my_custom_cpt_lables'); function my_custom_cpt_lables($labels){ /* set your labels as you see fit */ return $labels; }
filter wppizza custom post type arguments
@param: array (arguments of custom post type)
@return: array
example:
add_filter('wppizza_filter_cpt_args', 'my_custom_cpt_args'); function my_custom_cpt_args($args){ /* set your arguments as you see fit */ return $args; }
filter wppizza taxonomy labels
@param: array (labels of taxonomies)
@return: array
example:
add_filter('wppizza_filter_ctx_lbls', 'my_custom_tax_lables'); function my_custom_tax_lables($labels){ /* set your labels as you see fit */ return $labels; }
filter wppizza taxonomy arguments
@param: array (arguments of wppizza taxonomies)
@return: array
example:
add_filter('wppizza_filter_ctx_args', 'my_custom_tax_args'); function my_custom_tax_args($args){ /* set your argumentsas you see fit */ return $args; }]]>
determine if the current page the user is on is the WPPizza checkout page as set in WPPizza -> Order Settings -> Global
@return: bool – true if current page is checkout page, false if not.
example:
if(wppizza_is_checkout()){ /* do something if on checkout page*/ } /* using alias */ if(wppizza_is_orderpage()){ /* do something if on checkout page*/ }
determine if the current page the user is on is the page that contains the shortcode [wppizza type='orderhistory']
to display the users order history
@return: bool – true or false
example:
if(wppizza_is_orderhistory()){ /* do something if on users order history page*/ }
get all wppizza categories as set in WPPizza -> Categories
@return: array
example:
$wppizza_categories= wppizza_get_categories(); print_r($wppizza_categories); /* print array of categories */
get all wppizza menu items as set in WPPizza -> Menu Items
@return: array of objects
example:
$wppizza_menu_items = wppizza_get_menu_items(); print_r($wppizza_menu_items ); /* print array of wppizza menu items*/
get all wppizza additives as set in WPPizza -> Additives
@return: array
example:
$wppizza_all_additives= wppizza_all_additives(); print_r($wppizza_all_additives); /* print array of wppizza additives*/
determine if the current user has self pickup selected provided it generally enabled in WPPizza -> Order Settings -> Pickup
@return: bool – true if pickup, false if not.
example:
if(wppizza_is_pickup()){ /* do something if pickup selected*/ }
determine if the current user has nothing put into the cart yet
@return: bool – true if there’s nothing in the cart, false if not.
example:
if(wppizza_cart_is_empty()){ /* do something if nothing in cart*/ }
determine if the current user has something put into the cart (opposite of wppizza_cart_is_empty)
@return: bool – true if there’s something in the cart, false if not.
example:
if(wppizza_cart_has_items()){ /* do something if something's in the cart*/ }
get the contents of the cart in a multidimensional array (since version 3.2.7)
@return: array
example:
$wppizza_get_cart = wppizza_get_cart(); print_r($wppizza_get_cart); /* print full array of cart contents*/
get a summary of the cart parameters (totals, taxes etc) (since version 3.2.7)
@return: array
example:
$wppizza_cart_summary = wppizza_cart_summary(); print_r($wppizza_cart_summary); /* print array */
determine if the shop is open depending on settings in WPPizza -> Opening Times
@return: bool – true if shop is open, false if not.
example:
if(wppizza_is_shop_open()){ /* do something if shop's open */ }
determine if current time is within the current business day (as opening hours can cross midnight) between opening and closing time depending on settings in WPPizza -> Opening Times
– requires php 5.3+
@return: bool – true if it is, false if it is not.
example:
if(wppizza_is_current_businessday()){ /* do something if current time is within the current business day opening hours */ }
get all wordpress pages for current blog
@return: array of objects
example:
$wppizza_get_wordpress_pages= wppizza_get_wordpress_pages(); print_r($wppizza_get_wordpress_pages); /* print array of pages*/
get network sites/pages (current blog only if not in network setup)
@return: array
example:
$wppizza_get_networkpages = wppizza_get_networkpages(); print_r($wppizza_get_networkpages); /* print array of pages*/
get all wppizza sizes as set in WPPizza -> Meal Sizes
@return: array
example:
$wppizza_sizes_available= wppizza_sizes_available(); print_r($wppizza_sizes_available); /* print array of wppizza meal sizes*/
get url of WPPizza checkout page as set in WPPizza -> Order Settings -> Global
and/or WPPizza amend orderpage as set in WPPizza -> Order Form Settings -> Confirmationpage
(if used)
@param: str|false (default false or string of ‘orderpage’ or ‘amendorderlink’)
@return: mixed array|str
examples:
$wppizza_orderpages_urls = wppizza_page_links(); print_r($wppizza_orderpages_urls ); /* returns array of both urls / $wppizza_orderpage_url = wppizza_page_links('orderpage'); echo $wppizza_orderpage_url /*; prints url to order page set / $wppizza_amendorderlink_url = wppizza_page_links('amendorderlink'); echo $wppizza_amendorderlink_url; /* prints url to amend order page set /
format price according to options set in WPPizza -> Layout ->Prices / Currency Symbols
including spacing and currency and decimal formatting
@param: float (should be at least a numeric string . no commas or thousands separators !)
@return: str
example:
$formatted_price = wppizza_format_price(6.5); echo $formatted_price ; /* prints something like $ 6.50 */
format price according to options set in WPPizza -> Layout ->Prices / Currency Symbols
WITH decimal formatting but WITHOUT any spacing or currency symbols
@param: float (should be at least a numeric string . no commas or thousands separators !)
@return: str
example:
$formatted_price = wppizza_output_format_price(3.2); echo $formatted_price ; /* prints something like 3.20 */
If your theme does not provide for breadcrumbs, but you want to use them, you can do something like the following. Edit as required
@param: array
@param: array //optional
@param: array //optional
@param: array //optional
@param: int //optional
@param: int //optional
@return: array
example:
//only the first parameter is really needed for the breadcrumbs here, but for completeness all 6 are listed below add_filter('wppizza_loop_before_menu_items', 'prefix_add_wppizza_breadcrumbs', 10, 6); function prefix_add_wppizza_breadcrumbs($markup, $txt, $additives, $category, $max_num_pages, $post_count){ // default arguments are as follows $args = array(); $args['here_text'] = __( 'You are currently here!' ); $args['home_link'] = home_url('/'); $args['home_text'] = __( 'Home' ); $args['link_before'] = ''; $args['link_after'] = ''; $args['link_attr'] = ' rel="v:url" property="v:title"'; $args['delimiter'] = ' » '; // Delimiter between crumbs $args['before'] = ''; // Tag before the current crumb $args['after'] = '';// Tag after the current crumb // output the breadcrumbs according to arguments $markup['breadcrumbs'] = wppizza_breadcrumbs($args); return $markup; }
Additional filterhooks available you could use alternatively to the ‘wppizza_loop_before_menu_items’ above or even additionally if you like
- wppizza_loop_before_header - wppizza_loop_after_header - wppizza_loop_before_menu_items - wppizza_loop_after_menu_items - wppizza_loop_before_additives - wppizza_loop_after_additives - wppizza_loop_before_pagination - wppizza_loop_after_pagination]]>
if you want change any WPPizza option values depending on some arbitrary setting and or write a plugin that dynamically changes values or any other things that you can think of that needs a WPPizza option to be dynamically change in the frontend the following filter will probably be your main starting point
@param: array ($wppizza_options)
@return: array (return all/filtered options set for the WPPizza plugin)
example:
add_filter('wppizza_filter_options', 'my_prefix_my_options'); function my_prefix_my_options($wppizza_options){ /* do something that requires changing an option perhaps utilising some of the global functions that can be found here //docs.wp-pizza.com/developers/?section=global-wppizza-functions use print_r($wppizza_options) to get/see all wppizza options array the keys/values should be quite self-explanatory I would think so, as an example (though somewhat useless and just to demonstrate), closing the shop on pickup */ if(wppizza_is_pickup()){ $wppizza_options['openingtimes']['close_shop_now'] = true; } /* IMPORTANT: you MUST NOT EVER forget to return $wppizza_options here */ return $wppizza_options; }]]>
if you want run an action (i.e your own function/plugin) after an order has been successfully completed, you can hook into wppizza_on_order_execute
@param: int
@param: array (formatted array of order details)
@param: array (an array of print templates output as set in WPPizza ->Templates print can be added to be available as 3rd parameter in the action hook – see below)
@return: void
example:
add_action('wppizza_on_order_execute', 'my_prefix_my_action', 10, 3); function my_prefix_my_action($order_id, $order_details, $print_templates){ /* do something that happens after each order has bee completed */ }
if also want to have the output of a print template available in the function of the above action add the relevant id’s like so
add_filter('wppizza_on_order_execute_get_print_templates_by_id', 'my_prefix_my_filter'); function my_prefix_my_filter($template_ids){ /* add details of a template id defined in WPPizza -> Templates -> Print for it to be available in subsequent wppizza_on_order_execute action hook as 3rd parameter */ $template_ids[] = 3;/* get details of print template with id 3 */ return $template_ids; }]]>
if you want change currency symbols for a given currency or indeed need to add a new one in case your currency is missing from the 140+ already available
@param: array (array of all currencies with they array key being 3-letter ISO and the value being symbol you want to have displayed)
@return: array
example:
add_filter('wppizza_filter_currencies', 'myprefix_filter_currencies'); function myprefix_filter_currencies($curr){ /* example, changing the default symbol from € to EUR */ $curr['EUR'] = 'EUR'; /* example, adding a new currency ABC being the 3-letter ISO and # being the currency symbol to be displayed */ $curr['ABC'] = '#'; return $curr; }]]>