Integration into Packing Lists and Invoices


You have two options to integrate label image files into packing slips and invoices: by using a shortcode or calling a function in a hook.

Important: In the settings the image data type PNG has to be selected to integrate image files into other documents.

Shortcode

The shortcode [mame_bc_label_image] can be used to display the labels belonging to a WooCommerce order.

You can optionally pass three parameters to the shortcode:

  • width: the width of the image in px.
  • height: the height of the image in px.
  • newline: possible values: 0 , 1 (standard). The value1 will print each label on a new line if there are multiple labels available for one order.

Example:

[mame_bc_label_image width=600 height=400 newline=0]

Some invoice and packing slip plugin don’t run the shortcode since the code is not executed in the post loop and therefore there is no post id. In this case please use the function  Barcode_Order::print_label_images_from_woocommerce_order inside a hook function (see below).

Function call

By using the function Barcode_Order::print_label_images_from_woocommerce_order you can display label images on the packing slip / invoice of an order.

The function expects the following parameters:

  • WC_Order $order: the WooCommerce order object.
  • int $width (optional): width of the image.
  • int $height (optional): height of the image.
  • bool $newline (optional): standard true. The value true will print each label on a new line if there are multiple labels available for one order.

If you use the official WooThemes plugin WooCommerce Print Invoices & Packing Lists you could for example insert the following code into the functions.php file of your theme:

add_action( 'wc_pip_before_body', 'my_barcode_display_stamps_function', 10, 4 ); 
function my_barcode_display_stamps_function ($type, $action, $document, $order) {
        Barcode_Order::print_label_images_from_woocommerce_order($order); 
}

If the image does not display correctly, your server may require image paths instead of URLs. In that case the code would look like this:

add_action( 'wc_pip_before_body', 'my_barcode_display_stamps_function', 10, 4 ); 
function my_barcode_display_stamps_function ($type, $action, $document, $order) {       
    Barcode_Order::print_label_images_from_woocommerce_order($order, false, false, true, true); 
}

For other packing slip / invoice plugins, the code would have to be adapted according to the available actions.