Code39 barcodes were not loading on my site backend and not embedded well in the mails.
In includes/class-woocommerce-order-barcodes.php I fixed this by replacing lines 464 – 478:
// // Return an image (for emails and frontend order view).
// if ( $image ) {
// $barcode_url = $this->barcode_url( $order_id );
// ob_start();
// echo ”;
// echo ”;
// echo ”;
// /* @phpstan-ignore-next-line */
// require WC_ORDER_BARCODES_DIR_PATH . ‘/templates/barcode-image.php’;
// echo ”;
// echo ”;
// echo ”;
// return ob_get_clean();
// }
by:
// For email/frontend/admin, avoid the PNG endpoint and render inline barcode markup instead.
if ( $image ) {
// In admin and frontend, inline markup works better than the PNG endpoint on this setup.
if ( is_admin() ) {
$barcode_output = ( ‘datamatrix’ === $this->barcode_type ) ? ‘SVG’ : ‘HTML’;
$barcode_markup = $this->barcode_generator->get_generated_barcode( $barcode_text, $barcode_output );
ob_start();
echo ”;
echo ”;
echo ”;
echo $barcode_markup; // phpcs:ignore
echo ” . esc_html( $barcode_text ) . ”;
echo ”;
echo ”;
echo ”;
return ob_get_clean();
}
// For emails/front-end image contexts, embed the PNG directly as base64.
$barcode_png = $this->barcode_generator->get_generated_barcode( $barcode_text, ‘PNG’ );
if ( is_string( $barcode_png ) && ” !== $barcode_png ) {
$barcode_base64 = base64_encode( $barcode_png );
ob_start();
echo ”;
echo ”;
echo ”;
echo ”;
echo ” . esc_html( $barcode_text ) . ”;
echo ”;
echo ”;
echo ”;
return ob_get_clean();
}
// Fallback.
$barcode_output = ( ‘datamatrix’ === $this->barcode_type ) ? ‘SVG’ : ‘HTML’;
$barcode_markup = $this->barcode_generator->get_generated_barcode( $barcode_text, $barcode_output );
ob_start();
echo ”;
echo ”;
echo ”;
echo $barcode_markup; // phpcs:ignore
echo ” . esc_html( $barcode_text ) . ”;
echo ”;
echo ”;
echo ”;
return ob_get_clean();
}
Open
Last updated: March 19, 2026
0 comments
Log in to comment on this feature request.