Goodcom Printer

Filter examples to alter the goodcom printer output

wppizza_goodcom_printer_filter_xml_site

Using the 3 filters below as described will result in a print layout similar to this screenshot. The final layout will depend on actual order and customer values submitted.

@param: array(parameters)
@return: array(filtered parameters)

/* example : adding site url in header and add additional linebreak */
add_filter('wppizza_goodcom_printer_filter_xml_site', 'set_header');
function set_header($array){
	$array['values']['site_url']['enabled'] = true;
	$array['values']['site_url']['format_value_post'] = '\r\r';//add additional linebreak
return $array;
}
/* example : summarising important values */
/*
	the goodcom xml only allows for 8 segments, some of which are reserved
	so we use the filter below to add a pseudo segment underneath the 'site'
	parameters (even though they might or might not be displayed)
*/ 
add_filter('wppizza_goodcom_printer_filter_xml_site', 'set_custom_summary');
function set_custom_summary($array){
	
		//adding payment method 
		$array['values']['payment_method'] = array(
			'sort' => 1000,//sort order - first after everything in the site section
			'enabled' => true,//enabled (should be true else one might as well not do this anyway)
			'sKey' => 'ordervars',//section key , needs to be ordervars here
			'raw_value' => false,//using formatted value
			'align' =>'center',	//center
			'omit_label' => true,//omit label (i.e do not output Payment Method but only "Cash" or "Prepay")			
			'format_value_pre' => '------------Summary-----------\r',//add divider to first added parameter with label. total length should be 11 characters if set to bold by ending with \s\r instead of just \r (eg '\r--Summary--\s\r'), 30 chars if not . start with \r if linebreak is required above
			'format_value_post' => '\s\r',//'\s\r' to set payment_method value to bold
		);
		// pickup or delivery 
		$array['values']['order_type'] = array(
			'sort' => 1001,//sort order - second after everything in this section
			'enabled' => true,
			'sKey' => 'ordervars',
			'raw_value' => false,
			'align' =>'center',	//center
			'omit_label' => true,//omit label 			
			'format_value_pre' => '',//no pre format
			'format_value_post' => '\s\r',//set value to bold
		);				
			
		//adding payment due after site name 
		$array['values']['payment_due'] = array(
			'sort' => 1002,//sort order - third after everything in this section
			'enabled' => true,//enabled (should be true else one might as well not do this anyway)
			'sKey' => 'ordervars',//section key , needs to be ordervars here
			'new_label' => 'Due:',//change too long "Payment Due" to simple "To Pay" 
			'raw_value' => false,//set to true to us unformatted value (i.e price without currency to save space perhaps as it's bolded)
			'align' =>'center',	//center
			'omit_label' => false,//dont omit label 			
			'format_value_pre' => '',//no pre format
			'format_value_post' => '\s\r',//set value to bold
		);
		//adding customer telephone  number - make sure you have that field actually enabled on the order form or you will get php notices
		$array['values']['ctel'] = array(
			'sort' => 1003,//sort order - fourth after everything in this section
			'enabled' => true,//enabled (should be true else one might as well not do this anyway)
			'sKey' => 'customer',//section key , needs to be customer here
			'raw_value' => true,//must be true, as there is no specific value_formatted for customer vars
			'align' =>'center',	//center
			'omit_label' => false,//do not omit label 			
			'format_value_pre' => '',//no pre format
			'format_value_post' => '',//not bold
		);
		//adding total
		$array['values']['total'] = array(
			'sort' => 1004,//sort order - fifth after everything in this section
			'enabled' => true,//enabled (should be true else one might as well not do this anyway)
			'sKey' => 'summary',//section key , needs to be customer here
			'raw_value' => false,//show formatted value (i.e with currency symbol)
			'align' =>'center',	//center
			'omit_label' => false,//do not omit label 			
			'format_value_pre' => '',//no pre format
			'format_value_post' => '',//not bold
		);
	
    return $array;	
}
/* example : adding an arbitrary footer with divider */
add_filter('wppizza_goodcom_printer_filter_xml_footer', 'set_footer');
function set_footer($array){

	/* 
		display a footer, centered using spaces
		with a divider above the text
	*/
	$array['label']['enabled'] = true;
	$array['label']['localization'] = 'some arbitrary footer';
	$array['label']['align'] = array('center'=>' ', 'divider' => 'pre');//center using spaces, set center to '' to not align, 'divider' to false to omit divider, 'post' for divider below

return $array;
}

Additional Filter Examples

Filtering itemised order details: ‘wppizza_goodcom_printer_filter_xml_order’

@param: array(parameters)
@return: array(filtered parameters)

//example 1- remove prices from order items , 
//example 2- display prices unformatted (without currency symbol to perhaps save on space)
//example 3- dont display brackets around size
//example 4- dont display sizes at all (only a good idea if there is only ever 1 size )
add_filter('wppizza_goodcom_printer_filter_xml_order', 'format_order_items');
function format_order_items($array){
		
		
	//example 1 
	$array['values']['pricetotal_formatted']['enabled'] = false;
		
	//example 2 
	$array['values']['pricetotal_formatted']['enabled'] = false;
	$array['values']['pricetotal']['enabled'] = true;

	//example 3 
	$array['values']['price_label']['prefix'] = '';
	$array['values']['price_label']['suffix'] = '';

	//example 4
	$array['values']['price_label']['enabled'] = false;

    
    return $array;	
}	

 

Filtering ordervars labels: ‘wppizza_goodcom_printer_filter_xml_ordervars’

@param: array(parameters)
@return: array(filtered parameters)

//example 1- remove divider and label 
//example 2- dont center 
//example 3- center using "_" (underscore) character instead of "-"
//example 4- remove label and use defined character as divider
//example 5- set a different label
//example 6- bold label
add_filter('wppizza_goodcom_printer_filter_xml_ordervars', 'format_ordervars_label');
function format_ordervars_label($array){
		
	//example 1
	$array['label']['enabled'] = false;

	//example 2
	$array['label']['align'] = false;

	//example 3
	$array['label']['align']['center'] = '_';

	//example 4
	$array['label']['enabled'] = false;
	$array['label']['align']['center'] = '_';
	$array['label']['align']['divider'] = true;
		
	//example 5		
	$array['label']['localization'] = 'other text';		

	//example 6		
	$array['label']['format_post'] = '\s\r';		
		

    return $array;	
}	

 

Filtering ordervars values output: ‘wppizza_goodcom_printer_filter_xml_ordervars’

@param: array(parameters)
@return: array(filtered parameters)

//example 1- bold the order id 
//example 2- omit label from payment method and center value
//example 3- enable and display ipaddress before all other vars
//example 4- do not display date
//example 5- display transaction id, remove label, (bold it) and move it after order_type  
//example 6- use unformatted value (this might not always differ for all variables)
//example 7- using raw db values 
//example 8- do not display "please allolow x minutes etc etc 

add_filter('wppizza_goodcom_printer_filter_xml_ordervars', 'format_ordervars');
function format_ordervars($array){
	
	//example 1 
	$array['values']['order_id']['format_value_post'] = '\s\r';

	//example 2 
	$array['values']['payment_method']['omit_label'] = true;//simply omitting label
	$array['values']['payment_method']['align'] = 'center';//centering value
	
	//example 3 
	$array['values']['ip_address']['sort'] = 1;
	$array['values']['ip_address']['enabled'] = true;		

	//example 4 
	$array['values']['order_date']['enabled'] = false;

	//example 5 
	$array['values']['transaction_id']['sort'] = 55;//order type is 50
	$array['values']['transaction_id']['enabled'] = true;	
	$array['values']['transaction_id']['omit_label'] = true;
	$array['values']['transaction_id']['format_value_post'] = '\s\r';
	
	//example 6.1 NOT bolding , must perhaps add linebreak before if no label (depending on where it's displayed)
	$array['values']['transaction_id']['sort'] = 55;//order type is 50
	$array['values']['transaction_id']['enabled'] = true;	
	$array['values']['transaction_id']['omit_label'] = true;
	$array['values']['transaction_id']['format_value_pre'] = '\r';
	
	//example 7 
	$array['values']['order_date']['raw_value'] = true;// would display 2018-10-23 12:25:59 or similar instead of -depending on your site date/time format settings) October, 23 2018 12:25 or similar
	$array['values']['total']['raw_value'] = true;// would display 3000.95 instead of $3,000.00 (or similar, depending on locale)

	//example 8 
	$array['values']['pickup_delivery']['enabled'] = false;
				
return $array;	
}

 

Filtering (omitting some) customer information: ‘wppizza_goodcom_printer_filter_xml_customer’

@param: array(parameters)
@return: array(filtered parameters)

add_filter('wppizza_goodcom_printer_filter_xml_customer', 'format_customer_data');
function format_customer_data($array){
		
	/* omit name */		
	unset($array['values']['cname']);
	/* omit email */		
	unset($array['values']['cemail']);
	/* omit address */		
	unset($array['values']['caddress']);
	/* omit first custom  field */		
	unset($array['values']['ccustom1']);
	/* etc etc */
	
	/*
		the keys (cname, cemail etc) 
		correspond to the keys / formfields in "Wppizza->OrderForm"
		(hover your mouse over the "enabled" buttons to view the keys for each field)
		
	*/
	
    return $array;	
}	

 

Filtering (adding) SKU’s to title of each item using: ‘wppizza_goodcom_printer_filter_xml_order’

@param: array
@return: array

/* adding SKU's - if set/exist - before item title */
add_filter('wppizza_goodcom_printer_filter_xml_order', 'add_sku_to_title');
function add_sku_to_title($array){
	
	$array['values']['sku'] = array(
		'sort' => 5,//before everything else (the first naturally occurring string is 'quantity' with a priority of 10)
		'enabled' => true,//no point of setting this to anything else than true
		'type' => 'name',//left hand side (item name). use 'value' to add it to right hand side
		'prefix' => '',//if you want the sku's wrapped in brackets for example, set prefix to '(' and suffix to ')' 
		'suffix' => '',//if you want the sku's wrapped in brackets for example, set prefix to '(' and suffix to ')' 
	);


return $array;	
}

 

If your particular goodcom printer model allows for fonts to be somewhat bigger you will have fewer characters per line “to play with” and may have to adjust the maximum characters per line (for dividers etc). To do so , you can do the following (reducing the default 30 chars per line to 24 in this example)

@param: int
@return: int

add_filter('wppizza_goodcom_printer_filter_max_chars_default', 'myfilter_set_goodcom_default_maxchar');
function myfilter_set_goodcom_default_maxchar($maxchar){
	$maxchar = 24;
return $maxchar;
}

// if you also need to do the equivalent for the big/bold text of the printer (reducing the default 11 to 9 in this example)
add_filter('wppizza_goodcom_printer_filter_max_chars_bold', 'myfilter_set_goodcom_bold_maxchar');
function myfilter_set_goodcom_bold_maxchar($maxchar){
	$maxchar = 9;
return $maxchar;
}

 

Ingredients (if using the “WPPizza Add Ingredients” plugin) are simply separated by | . Use the below filter to use a different divider if you wish.

@param: str
@return: str

add_filter('wppizza_goodcom_printer_filter_ai_divider', 'my_ai_divider' );
function my_ai_divider($str){
    $str = '|';/* replace | with whatever you want to use as divider between ingredients */
return $str;
}