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).
Advertisement
Answer
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
:
if ( ! function_exists( 'yith_wc_barcodes_and_qr_filter_call_back' ) ) { add_action( 'yith_wc_barcodes_and_qr_filter', 'yith_wc_barcodes_and_qr_filter_call_back', 10, 1 ); function yith_wc_barcodes_and_qr_filter_call_back( $id ) { ob_start(); $css = ob_get_clean(); YITH_YWBC()->show_barcode( $id, true, $css ); } }
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() );