• Resolved hdawc

    (@hdawc)


    I’ve seen many people ask how to use the ‘WC Barcode’ plugin, with this plugin, but most notably the ability to print barcodes through Simba Hosting’s CloudPrint and now the new PrintNode plugins (which work very well I might add!).

    It’s clear to see why this could be useful, and I’ve found a solution I hope at least a few people use ??

    A lot of posts mention this to get the barcode:
    //echo WC_Order_Barcodes()->display_barcode( $order->get_id() );

    However, even with this PDF plugin installed, the WooCommerce Automatic Order Printing plugin doesn’t show barcodes when printing. So, to get around this, I’ve embedded a Barcode ‘font’ from Google Fonts.

    Instead of the WC Barcodes plugin, we can just use the the Order ID itself from WooCommerce.

    Assuming you have copied from the Automatic Order Printing plugin, and are editing /yourtheme/templates/cloud-print.php, here’s what you need to do.

    Near the top of the file (in the <head>), add this
    <link href="https://fonts.googleapis.com/css2?family=Libre+Barcode+39&display=swap" rel="stylesheet">
    and this:

    <style>
    #barcode{font-family:'Libre Barcode 39';font-size:40px;text-align:center;}
    </style>

    There might already by <style> tags in the cloud-print.php file, so just add the bit between the two tags. You can make the font size larger than 40px if you like. I was printing on a label printer, so had to keep it small.
    You’ll also need to take into account the longest barcode you might need as you don’t want it to run off the paper (if you’re using A5 for example).

    Then simply add this where you want to put the barcode, I added mine at the bottom:

    $barcode = $order->get_id();
    ?>
    <br>
    <div id="barcode">*<?php echo $barcode ?>*</div>
    <br>
    <?php
    • The first line gets the plain Woo Order ID.
    • The second closes PHP as we are about to use HTML
    • The third and fifth lines add <br>, which create new lines above and below to give the barcode space.
    • The fourth creates a <div>, opens PHP to put the barcode, closes PHP and closes the <div>.
      Notice the asterisks, they are important, as the ‘Code 39’ barcode specification requires these marks, so scanners can read them. You can use Code 128 if you prefer.
    • The last line opens the PHP again so you can add or use other code.
    • If you want to see text below the barcode, change family=Libre+Barcode+39 to family=Libre+Barcode+39+Extended+Text from the Google Fonts link above.

      This is particularly useful if you also want to create a small mobile app that scans your barcode, creates a link and opens the relevant order edit page on the WordPress admin. I won’t go into that here though.

      I’ll follow up if anyone has any questions.

      (I appreciate that this post is not 100% about this plugin, but as I’ve seen a few questions regarding using the Auto Print by the same Developers on this forum, it made sense to add this here. Hope it helps!)

    • This topic was modified 4 years ago by hdawc.
    • This topic was modified 4 years ago by hdawc.
    • This topic was modified 4 years ago by hdawc.
    • This topic was modified 4 years ago by hdawc. Reason: simplifying explanations
    • This topic was modified 4 years ago by hdawc.
    • This topic was modified 4 years ago by hdawc. Reason: spelling
    • This topic was modified 4 years ago by hdawc.
Viewing 1 replies (of 1 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Thanks for sharing this!

    To anyone else reading this: the above code is specific to WooCommerce Automatic Order Printing and the template instructions apply to built in templates of that plugin rather than the PDF invoices & packing slips plugin. That means that the above instructions do not apply to the plugin that this forum is for.

Viewing 1 replies (of 1 total)
  • The topic ‘[SOLVED] Barcode printing to WooCommerce Automatic Order Printing’ is closed to new replies.