I need to display the barcode of the product on the invoice or delivery note, I try to do it with this code but it does not show the barcode image:
<?php
echo get_post_meta( $product_id, '_ywbc_barcode_image', true );
?>
I am using the YITH WooCommerce Barcodes and QR Codes plugin, which adds a barcode for each product, in the following image you can see the meta data that the plugin adds (Product Post Meta).
2
Answers
I’m not too familiar with this plugins; however, from your screenshot it looks like
_ywbc_barcode_image
does not have a value.It might be considered slightly hacky, but why not build the filename yourself? Example:
That’ll give you a value of
Image5582_QRcode_5582.png
. Which you can use to insert where needed; such-as inside an image tag.You can add a
do_action
wherever you like the order barcode to appear, assuming you have access to either the$order
object or order id, like this:do_action ( 'yith_wc_barcodes_and_qr_filter', $order->get_id() );
You can then use that to call an action that will display the barcode on all locations you’ve added the
do_action
:This last part goes in the functions.php of your (child)theme or should be added with a plugin like Code Snippets.
If you need the product barcode you will have to use the product ID instead of the order ID, assuming you have access to the
$product
object.do_action ( 'yith_wc_barcodes_and_qr_filter', $product->get_id() );