在发票或送货单上显示每个产品的条形码,woocommerce

我需要在发票或送货单上显示产品的条形码,我尝试使用此代码执行此操作,但它不显示条形码图像:

<?php
    echo get_post_meta( $product_id, '_ywbc_barcode_image', true );
        ?>

我正在使用 YITH WooCommerce 条形码和 QR 代码插件,它为每个产品添加条形码,在下图中您可以看到该插件添加的元数据(产品帖子元)。

https://img1.mukewang.com/64e07bbb0001fe8b05920242.jpg

心有法竹
浏览 107回答 2
2回答

小唯快跑啊

do_action假设您有权访问对象或订单 ID,您可以在任意位置添加订单条形码$order,如下所示:do_action ( 'yith_wc_barcodes_and_qr_filter', $order->get_id() );然后,您可以使用它来调用一个操作,该操作将在您添加的所有位置上显示条形码do_action:if ( ! function_exists( 'yith_wc_barcodes_and_qr_filter_call_back' ) ) {&nbsp; &nbsp; add_action( 'yith_wc_barcodes_and_qr_filter', 'yith_wc_barcodes_and_qr_filter_call_back', 10, 1 );&nbsp; &nbsp; function yith_wc_barcodes_and_qr_filter_call_back( $id ) {&nbsp; &nbsp; &nbsp; &nbsp; ob_start();&nbsp; &nbsp; &nbsp; &nbsp; $css = ob_get_clean();&nbsp; &nbsp; &nbsp; &nbsp; YITH_YWBC()->show_barcode( $id, true, $css );&nbsp; &nbsp; }}最后一部分位于您(子)主题的functions.php中,或者应该使用代码片段之类的插件添加。如果您需要产品条形码,则假设您有权访问该对象,则必须使用产品 ID 而不是订单 ID $product。do_action ( 'yith_wc_barcodes_and_qr_filter', $product->get_id() );

桃花长相依

我对这个插件不太熟悉;但是,从您的屏幕截图来看,它似乎_ywbc_barcode_image没有价值。它可能被认为有点 hacky,但为什么不自己构建文件名呢?例子:$barcodeFile = sprintf( "Image%s_QRcode_%s.png", array(&nbsp; &nbsp; get_post_meta( $product_id, '_ywbc_barcode_value', true ),&nbsp; &nbsp; get_post_meta( $product_id, '_ywbc_barcode_value', true ) ) );这会给你一个值Image5582_QRcode_5582.png。您可以使用它来插入需要的地方;例如在图像标签内。<img src="<?php echo site_url(); ?>/wp-content/uploads/yith-barcodes/<?php echo $barcodeFile; ?>">
打开App,查看更多内容
随时随地看视频慕课网APP