Print Template
Developer Documentation

Versions 4.0.1 and above for Print Manager for WooCommerce plugin

Overview

Print Manager plugin supports the ability to add Custom Print Templates as plugin add-ons. 

The Custom Print Template functionality for the Print Plugin would be the recommended solution for any custom fields required to be added or removed to a print-out receipt template or compatibility with other plugins not supported by default in the print templates included.

The print templates support a global $order variable, using $order->get_meta. This allows you to develop a Custom Print Template and add or remove all the fields you may require in the print-out receipt layout you want.

Important Note: We don’t recommend modifying the default templates under the /templates directory of the plugin. Print Manager plugin updates will override the modified template. Plus, we can’t guarantee the template format you modified will work in the future. We can commit to supporting the Custom Print Template solution in future releases as the correct solution for custom templates working with the plugin.


Plugin Development Structure 

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.

ZprintTemplates::registerTemplate – static method, require object, implements `ZprintTemplateIndex` interface

ZprintTemplateIndex

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 ZprintTemplateOptions 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

Zprintget_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

ZprintOrder::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 ZprintDocument 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 Print Template Structure 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 to the Print Manager plugin.

Buy Now Sample Print Template from Marketplace

*Sample Print Template Included in Plus Plan or Higher.

How to Install

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”. 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.

Extending Third-party Plugins Meta Data Support for the Templates

WP Actions

Use the provided actions to add any custom data to specific locations of the templates.

After Shipping Details

Zprinttemplatescustomer-htmlafterShippingDetails, passed argument: int $order_id
Zprinttemplatescustomer-plainafterShippingDetails, passed argument: int $order_id
Zprinttemplatesdetails-htmlafterShippingDetails, passed argument: int $order_id
Zprinttemplatesdetails-plainafterShippingDetails, passed argument: int $order_id
Zprinttemplatesorder-htmlafterShippingDetails, passed argument: int $order_id
Zprinttemplatesorder-plainafterShippingDetails, passed argument: int $order_id

Before Footer

Zprinttemplatescustomer-htmlbeforeFooter, passed argument: int $order_id
Zprinttemplatescustomer-plainbeforeFooter, passed argument: int $order_id
Zprinttemplatesdetails-htmlbeforeFooter, passed argument: int $order_id
Zprinttemplatesdetails-plainbeforeFooter, passed argument: int $order_id

End

Zprinttemplatesorder-htmlend, passed argument: int $order_id
Zprinttemplatesorder-plainend, passed argument: int $order_id

Action Usage Example
add_action( 'Zprinttemplatescustomer-htmlafterShippingDetails', 'afterShippingDetails', 10, 1 );function afterShippingDetails( int $order_id ): void {echo 'My custom data after shipping details';}

WP Filters

Use the provided filters to modify the existing data in the templates.

Order Item Meta

Zprinttemplatescustomer-htmlorderItemMeta, filterable value: array $meta
Zprinttemplatescustomer-plainorderItemMeta, filterable value: array $meta
Zprinttemplatesdetails-htmlorderItemMeta, filterable value: array $meta
Zprinttemplatesdetails-plainorderItemMeta, filterable value: array $meta
Zprinttemplatesorder-htmlorderItemMeta, filterable value: array $meta
Zprinttemplatesorder-plainorderItemMeta, filterable value: array $meta

Order Item RAW Meta

Zprinttemplatescustomer-htmlorderItemRawMeta, filterable value: array $meta, passed argument: WC_Order_item $item
Zprinttemplatescustomer-plainorderItemRawMeta, filterable value: array $meta, passed argument: WC_Order_item $item
Zprinttemplatesdetails-htmlorderItemRawMeta, filterable value: array $meta, passed argument: WC_Order_item $item
Zprinttemplatesdetails-plainorderItemRawMeta, filterable value: array $meta, passed argument: WC_Order_item $item
Zprinttemplatesorder-htmlorderItemRawMeta, filterable value: array $meta, passed argument: WC_Order_item $item
Zprinttemplatesorder-plainorderItemRawMeta, filterable value: array $meta, passed argument: WC_Order_item $item

Filter Usage Example
add_filter( 'Zprinttemplatescustomer-htmlorderItemMeta', 'orderItemMeta', 10, 1 );function orderItemMeta( array $meta ): array {// Do something with metareturn $meta;}