skip to Main Content

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).
Meta Datos Barcode Product

2

Answers


  1. 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:

    $barcodeFile = sprintf( "Image%s_QRcode_%s.png", array(
        get_post_meta( $product_id, '_ywbc_barcode_value', true ),
        get_post_meta( $product_id, '_ywbc_barcode_value', true ) ) );
    

    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.

    <img src="<?php echo site_url(); ?>/wp-content/uploads/yith-barcodes/<?php echo $barcodeFile; ?>">
    
    Login or Signup to reply.
  2. 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() );

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search