How to add a barcode to the WooCommerce PDF Invoices & Packing Slips Plugin

In Order Barcodes for WooCommerce by dan@plugindistrict.com

If you are using our Order Barcodes Plugin, there’s a good chance that you are also using the WooCommerce PDF Invoices & Packing Slips plugin. You can now add the Order Barcode to your Invoices and Packing Slips by following these simple steps. Please reach out if you have any questions or issues.

UPDATE: The Order Barcodes Plugin has been updated to handle this functionality, v2.1. Only proceed with these steps if you plan to keep using an older version of the plugin.

Step 1: Unzip the WooCommerce PDF Invoice & Packing Slips plugin

Unzip the plugin on your local machine.

Step 2: Open the template files

Open the following template files in a text editor, like Notepad++ or VS Code:

  • templates\Simple\invoice.php
  • templates\Simple\packing-slip.php

Step 3: Add the PHP code snippet

Add the following line of PHP code after the if statement on the header table

$barcodetype = (get_option('plugindistrict_orderbarcodes_barcodetype') == '' ? 'code128' : get_option('plugindistrict_orderbarcodes_barcodetype'));

Step 4: Add the barcode DIV

Copy the following:

<div class="pd_order_barcode_div" style="text-align: center; margin: 10px;">
     <img class="pd_order_barcode" style="display: block; margin-left: auto; margin-right: auto;" src="https://2tfh7u96zl.execute-api.us-east-1.amazonaws.com/added-jest-tests/barcode?type=<?php echo $barcodetype.'&value='.(($barcodetype == 'qrcode') ? $checkinpath . '?orderid='.$order->get_order_number() : $order->get_order_number()).'&includeText='.(get_option('plugindistrict_orderbarcodes_showtextupc') == 1 ? 'true' : 'false'); ?>" />
</div>

Paste it below the shop-address div

<td class="shop-info">
     <div class="shop-name"><h3><?php $this->shop_name(); ?></h3></div>
     <div class="shop-address"><?php $this->shop_address(); ?></div>
     <div class="pd_order_barcode_div" style="text-align: center; margin: 10px;">
          <img class="pd_order_barcode" style="display: block; margin-left: auto; margin-right: auto;" src="https://2tfh7u96zl.execute-api.us-east-1.amazonaws.com/added-jest-tests/barcode?type=<?php echo $barcodetype.'&value='.(($barcodetype == 'qrcode') ? $checkinpath . '?orderid='.$order->get_order_number() : $order->get_order_number()).'&includeText='.(get_option('plugindistrict_orderbarcodes_showtextupc') == 1 ? 'true' : 'false'); ?>" />
     </div>
</td>

Step 5: Save any file changes and ZIP

After saving any changes, right click on the top level plugin folder and ZIP it up.

Step 6: Upload and Activate the updated plugin ZIP file

Final Result

Example packing slip with QR Code