-
Notifications
You must be signed in to change notification settings - Fork 2
Developer Guide [en_US]
Welcome to the developer's guide for customizing the PeproDev Ultimate Invoice plugin. This guide will help you add custom invoice templates and macros to enhance the functionality of your invoices. Whether you need to create a unique template or add dynamic content, this guide has got you covered.
To add a custom invoice template, follow these steps:
-
Copy an Existing Template:
- First, copy one of the existing templates provided by the PeproDev Ultimate Invoice plugin.
-
Modify the Template:
- Make the necessary changes to your copied template as per your requirements.
-
Register the New Template:
- Use the following code snippet to register your new template with the plugin. Place this code in your theme's
functions.phpfile or a custom plugin.
- Use the following code snippet to register your new template with the plugin. Place this code in your theme's
/**
* Add custom template to Invoice Templates list
* You can later select this Template from Ultimate Invoice Theming Settings
*
* Snippet by: Amirhp.Com
* Tested upto: WooCommerce: 9.x / WordPress: 6.6.x / Ultimate Invoice: 2.x
*/
add_filter("puiw_get_templates_list", function ($templates) {
$templates[] = plugin_dir_path(__FILE__) . "invoice-template/default.cfg";
return $templates;
}, 10, 1);-
Set the New Template:
- Go to the Ultimate Invoice settings and select the newly added template as your default invoice template.
If you need to add new dynamic parameters (macros) to your invoice template, follow these steps:
/**
* Add Custom dynamic params to Invoice Template
* Use as {{{delivery_date}}} and {{{delivery_barcode}}}
*
* Snippet by: Amirhp.Com
* Tested upto: WooCommerce: 9.x / WordPress: 6.6.x / Ultimate Invoice: 2.x
*/
add_filter("puiw_get_default_dynamic_params", function($array_macros, $wc_order) {
$order = wc_get_order($wc_order);
$opts["delivery_date"] = $order->get_meta("_shipping_puiw_invoice_shipdate", true);
$opts["delivery_barcode"] = $order->get_meta("_shipping_puiw_invoice_track_id", true);
return $array_macros;
}, 10, 2);To ensure that certain macros retain their English digits (e.g., for tracking numbers or codes), use the following hook:
/**
* Add {{{delivery_barcode}}} to Preserved Numbers as English digits list
*
* Snippet by: Amirhp.Com
* Tested upto: WooCommerce: 9.x / WordPress: 6.6.x / Ultimate Invoice: 2.x
*/
add_filter("puiw_printinvoice_preserve_english_numbers", function($array_macros, $options, $wc_order) {
array_push($array_macros, "delivery_barcode");
return $array_macros;
}, 10, 3);If you need to prevent the sanitization of HTML within a macro, use the following snippet:
/**
* Add {{{delivery_barcode}}} to Preserved HTML Tags list
* If this macro contain HTML elements, it won't be sanitized
*
* Snippet by: Amirhp.Com
* Tested upto: WooCommerce: 9.x / WordPress: 6.6.x / Ultimate Invoice: 2.x
*/
add_filter("puiw_printinvoice_preserve_html_tags", function($array_macros, $options, $wc_order) {
array_push($array_macros, "delivery_barcode");
return $array_macros;
}, 10, 3);We hope this guide helps you customize the PeproDev Ultimate Invoice plugin to suit your needs. If you have any questions or run into any issues, feel free to reach out to us.