Developer Documents
Print Template 

Versions 3.0.1 and above
Adding custom templates:

To init custom templates after loading zprint call wp hook zprint_loaded

this will prevent plugin loading errors by using zprint API add_action('zprint_loaded', 'your_plugin_init_function_name');

Now the zprint_loaded – wp action, will be called after successfully loading zprint.

\Zprint\Templates::registerTemplate – static method, require object, implements `\Zprint\Template\Index` interface

\Zprint\Template\Index

required to implement methods in your class:
getName() – return name of your template (string)
getSlug() – return slug (string)
getPath($format) – accept $format (`plain`, `html`), return path to layout file (string)
getFormats() – return assoc array of formats, indicate which formats supports your template type, for example:
['html' => true, 'plain' => false].

Supports custom formats (for example: html): ['key_format' => 'Format name']

For custom options for your template, implement \Zprint\Template\Options interface, renderOptions, processOptions methods.
renderOptions($options) – accept current options assoc array, should render html with input to display them in location form
processOptions($options) – accept current options assoc array, should return new assoc array with data. You can access to new data by $_POST

In each template file you can access a few data and settings variables.
$templateOptions – assoc array include current template options

About shipping settings:

$location_data['shipping']['method'] – show shipping method
$location_data['shipping']['billing_shipping_details'] – show billing and shipping details
$location_data['shipping']['customer_details'] – show customer details
$location_data['shipping']['cost'] – show shipping cost

Additional useful methods and functions:

\Zprint\get_appearance_setting($name), accept name setting from General tab Print Settings.

Allowed names: logo,Order HeaderCheck HeaderCompany NameCompany InfoOrder Details HeaderFooter Information #1Footer Information #2

Return string or src path for logo

\Zprint\Order::getHiddenKeys() return array of keys for order item meta (item_meta from $order->get_items()) which should not display.

You can apply own keys by woocommerce_hidden_order_itemmeta filter.

Plain output format:

class \Zprint\Document include static methods to format strings:

Document::centerLine($string) – printer centered string
Document::emptyLine() = print empty string
Document::symbolsAlign($left, $right) – print two string parts joined by spaces in column format
Document::line($string) – print string in line

These methods supports word wrap. You can enable Print symbols for layout debug in location settings. It replaces the align spaces to dots for better layout debug.

 

Sample Custom Template
Purchase Sample Print Template for WooCommerce GCP Plugin

The sample print template is a shell of a template, allowing you to easily customize for the Print out format. Make changes to the html and css files to customize the layout and content for the print-out.

The sample print template is a plugin add-on. If you purchase the sample file. Go to your WordPress admin, plugins page. Click Add New. Upload and Activate the plugin. You will see a plugin installed labeled “Sample Print Template GCP”. The sample custom template is now active for selection and used by the Print Plugin. Now go to Print Settings, click Location tab, and select a print location. Under the template section, click the drop down, you will now see the template “Fancy” for selection.

OLDER Versions 2.1.2
Adding custom templates:

Filter Zprint\getTemplates, accept $templates – basic template list.
Return templates assoc array (template label => template name), allows you to add your template in select drop down.

Applying new template:
add_filter('Zprint\getTemplates', function ($templates) {
	$templates['fancy'] = 'Fancy';
	return $templates;
});

Also you need to specify the path to your template.

Filter Zprint\getTemplatePath, accept $templatePath – basic template path (try finding template in default directory), $template – template label (fancy in example), $format – format output html or plain.

Return absolute path to template.

Setting path:
add_filter('Zprint\getTemplatePath', function ($path, $template, $format) {
	if ($template === 'fancy') {
		$path = __DIR__ . '/template-' . $format . '.php';
	}
	return $path;
}, 10, 3);

In each template file you can access a few data and settings variables.

$order – instance of \WC_Order, you can get any information about order from WC, check WC Documentation as reference for more information.

$location_details – assoc array include many settings. For Example, like format, font settings, shipping.

For font settings (css) you can also use these aliases: $fontSize$fontWeight$headerSize$headerWeight

About shipping settings:

$location_data['shipping']['method'] – show shipping method
$location_data['shipping']['billing_shipping_details'] – show billing and shipping details
$location_data['shipping']['customer_details'] – show customer details
$location_data['shipping']['cost'] – show shipping cost

Additional useful methods and functions:

\Zprint\get_appearance_setting($name), accept name setting from General tab Print Settings.

Allowed names: logo,Order HeaderCheck HeaderCompany NameCompany InfoOrder Details HeaderFooter Information #1Footer Information #2

Return string or src path for logo

\Zprint\Order::getHiddenKeys() return array of keys for order item meta (item_meta from $order->get_items()) which should not display.

You can apply own keys by woocommerce_hidden_order_itemmeta filter.

Plain output format:

class \Zprint\Document include static methods to format strings:

Document::centerLine($string) – printer centered string
Document::emptyLine() = print empty string
Document::symbolsAlign($left, $right) – print two string parts joined by spaces in column format
Document::line($string) – print string in line

These methods supports word wrap. You can enable Print symbols for layout debug in location settings. It replaces the align spaces to dots for better layout debug.