Dear 8Theme Support Team,
I am writing to you regarding an integration challenge we are facing with your product.
We are actively using the “Barcode Generator for WooCommerce”, a third-party plugin, which successfully adds the capability to display EAN codes on our single product pages. The EAN values for each product are managed and stored within a product meta field, specifically accessible via an HTML input field named bargeno_meta_barcode
(e.g., <input type="text" name="bargeno_meta_barcode" class="text" value="123456789">
).
Our primary objective now is to extend this functionality to our Woocommrce PDF invoices, so that the corresponding EAN barcode is displayed next to each product line item on the invoice itself.
We have attempted to achieve this by writing a custom PHP snippet. This snippet is designed to retrieve the EAN value directly from the bargeno_meta_barcode field (provided by the BGW plugin) and then utilize TCPDF’s barcode generation capabilities within the CreateInvoice method of the WooPdfInvoice class (which is part of WooCommerce PDF Invoice). However, despite our efforts, the barcodes are currently not appearing on the generated PDF invoices.
To assist with troubleshooting, we can provide the following:
• Details on the HTML input field (<input type="text" class="short" style="" name="bargeno_meta_barcode" id="bargeno_meta_barcode" value="123456789" placeholder="Zadajte vlastnú hodnotu EAN">
) where the EAN value is entered.
• The tcpdf_barcodes_1d.php
file, which contains the TCPDFBarcode class (a common library for 1D barcode generation that we are using in conjunction).
• The woo-pdf-invoice.class.php
file, which outlines the WooPdfInvoice class that handles our PDF invoice generation.
• The specific PHP code snippet we have developed based on the bargeno_meta_barcode
field, which is intended to display the barcode on the invoice.
Our Current Challenge: We understand that neither the Barcode Generator for WooCommerce nor the WooCommerce PDF Invoice plugins are direct products of yours. Unfortunately, we do not possess a direct purchase code for the Woocommerce PDF Invoice plugin, which has made our attempts to contact RightPress support directly for assistance challenging.
Could you please guide us on the correct and supported method to display the dynamically generated EAN barcodes (sourced from “Barcode Generator for WooCommerce” plugin) on each product line item within the Woocommerce PDF Invoices?
Here is the php snippet we tried to use in the woo-pdf.invoice.class.php – a file that handles invoice structure – under function public function CreateInvoice()
// Retrieve barcode value from product meta
$barcode_value = $_product->get_meta('bargeno_meta_barcode');
if (!empty($barcode_value)) {
// Assuming EAN13 for standard product barcodes, adjust to 'EAN8' if necessary
$barcode_type = 'EAN13';
// Remove non-numeric characters and validate length for EAN13 (12 or 13 digits)
$cleaned_barcode_value = preg_replace('/[^0-9]/', '', $barcode_value);
if (strlen($cleaned_barcode_value) == 12 || strlen($cleaned_barcode_value) == 13) {
// Define barcode position and dimensions
$barcode_x = 45; // X coordinate, slightly indented like meta information
$barcode_y = $this->GetY() + 5; // Y coordinate, below the previous element (meta/images), add some padding
$barcode_width = 70; // Width of the barcode
$barcode_height = 15; // Height of the barcode
$font_size_barcode = 8; // Font size for the barcode text
// Set font for barcode text
$this->SetFont('helvetica', '', $font_size_barcode);
// Set TCPDF barcode styles
$style = array(
'border' => false,
'padding' => 'auto',
'fgcolor' => array(0, 0, 0), // Black foreground
'bgcolor' => array(255, 255, 255), // White background
'text' => true, // Show the barcode value as text below the barcode
'font' => 'helvetica',
'fontsize' => $font_size_barcode,
'stretchtext' => 4,
);
// Draw the barcode
$this->write1DBarcode(
$cleaned_barcode_value,
$barcode_type,
$barcode_x,
$barcode_y,
$barcode_width,
$barcode_height,
'',
$style,
'N' // No alignment, N for next line
);
// Update the Y position for the next elements (e.g., next product row)
$y = $this->GetY() + 5; // Add some padding after the barcode
} else {
// Optional: Log if barcode value length is not valid for EAN13/EAN8
error_log("WooPDFInvoice Barcode Error: Invalid barcode value length for product ID " . $_product->get_id() . ". Value: " . $barcode_value);
}
}
Thank you for your time and consideration.
Best regards,
Filip