问题描述
我想在带有 barcode/ISBN
的电子邮件订单确认电子邮件中的价格旁边添加一列。
我正在使用插件:WooCommerce Barcode & ISBN
每个产品看起来都是这样:
以及后端的每个产品的内部:
我已经有了该列和所有内容,我就是不知道如何在 PHP 中“获取”条形码/ISBN。
我在 email-order-details
中的代码(创建/添加列的位置):
defined( 'ABSPATH' ) || exit;
$text_align = is_rtl() ? 'right' : 'left';
do_action( 'woocommerce_email_before_order_table',$order,$sent_to_admin,$plain_text,$email ); ?>
<h2>
<?PHP
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
$after = '</a>';
} else {
$before = '';
$after = '';
}
/* translators: %s: Order ID. */
echo wp_kses_post( $before . sprintf( __( '[Order #%s]','woocommerce' ) . $after . ' (<time datetime="%s">%s</time>)',$order->get_order_number(),$order->get_date_created()->format( 'c' ),wc_format_datetime( $order->get_date_created() ) ) );
?>
</h2>
<div>
<h3 style="text-align:<?PHP echo esc_attr( $text_align ); ?>;"><?PHP esc_html_e( 'Ordermeddelande/Önskat Leveransdatum:
','woocommerce' ); ?></h3>
<p style="text-align:<?PHP echo esc_attr( $text_align ); ?>;"><?PHP echo wp_kses_post( nl2br( wptexturize( $order->get_customer_note() ) ) ); ?></p>
</div>
<div style="margin-bottom: 40px;">
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue',Helvetica,Roboto,Arial,sans-serif;" border="1">
<thead>
<tr>
<th class="td" scope="col" style="text-align:<?PHP echo esc_attr( $text_align ); ?>;"><?PHP esc_html_e( 'Product','woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?PHP echo esc_attr( $text_align ); ?>;"><?PHP esc_html_e( 'Quantity','woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?PHP echo esc_attr( $text_align ); ?>;"><?PHP esc_html_e( 'Price','woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?PHP echo esc_attr( $text_align ); ?>;"><?PHP esc_html_e( 'á pris','woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?PHP echo esc_attr( $text_align ); ?>;"><?PHP esc_html_e( 'Rek ut / Streckkod','woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?PHP
echo wc_get_email_order_items( // PHPcs:ignore wordpress.Security.EscapeOutput.OutputNotEscaped
$order,array(
'show_sku' => $sent_to_admin,'show_image' => false,'image_size' => array( 32,32 ),'plain_text' => $plain_text,'sent_to_admin' => $sent_to_admin,)
);
?>
</tbody>
<tfoot>
<?PHP
$item_totals = $order->get_order_item_totals();
if ( $item_totals ) {
$i = 0;
foreach ( $item_totals as $total ) {
$i++;
?>
<tr>
<th class="td" scope="row" colspan="4" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; <?PHP echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?PHP echo wp_kses_post( $total['label'] ); ?></th>
<td class="td" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; <?PHP echo ( 1 === $i ) ? 'border-top-width: 4px;' : ''; ?>"><?PHP echo wp_kses_post( $total['value'] ); ?></td>
</tr>
<?PHP
}
}
if ( $order->get_customer_note() ) {
?>
<?PHP
}
?>
</tfoot>
</table>
</div>
<?PHP do_action( 'woocommerce_email_after_order_table',$email ); ?>
在 email-order-items
里面(我猜我应该放条形码/ISBN 代码的地方)现在它现在显示任何带有条形码/ISBN 代码的内容:
defined( 'ABSPATH' ) || exit;
$text_align = is_rtl() ? 'right' : 'left';
$margin_side = is_rtl() ? 'left' : 'right';
foreach ( $items as $item_id => $item ) :
$product = $item->get_product();
$sku = '';
$purchase_note = '';
$image = '';
if ( ! apply_filters( 'woocommerce_order_item_visible',true,$item ) ) {
continue;
}
if ( is_object( $product ) ) {
$sku = $product->get_sku();
$purchase_note = $product->get_purchase_note();
$image = $product->get_image( $image_size );
}
?>
<tr class="<?PHP echo esc_attr( apply_filters( 'woocommerce_order_item_class','order_item',$item,$order ) ); ?>">
<td class="td" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; vertical-align: middle; font-family: 'Helvetica Neue',sans-serif; word-wrap:break-word;">
<?PHP
// Show title/image etc.
if ( $show_image ) {
echo wp_kses_post( apply_filters( 'woocommerce_order_item_thumbnail',$image,$item ) );
}
// Product name.
echo wp_kses_post( apply_filters( 'woocommerce_order_item_name',$item->get_name(),false ) );
// SKU.
if ( $show_sku && $sku ) {
echo wp_kses_post( ' (#' . $sku . ')' );
}
// allow other plugins to add additional product information here.
do_action( 'woocommerce_order_item_Meta_start',$item_id,$plain_text );
wc_display_item_Meta(
$item,array(
'label_before' => '<strong class="wc-item-Meta-label" style="float: ' . esc_attr( $text_align ) . '; margin-' . esc_attr( $margin_side ) . ': .25em; clear: both">',)
);
// allow other plugins to add additional product information here.
do_action( 'woocommerce_order_item_Meta_end',$plain_text );
?>
</td>
<td class="td" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',sans-serif;">
<?PHP
$qty = $item->get_quantity();
$refunded_qty = $order->get_qty_refunded_for_item( $item_id );
if ( $refunded_qty ) {
$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * -1 ) ) . '</ins>';
} else {
$qty_display = esc_html( $qty );
}
echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity',$qty_display,$item ) );
?>
</td>
<td class="td" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',sans-serif;">
<?PHP echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?>
</td>
<td class="td" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',sans-serif;">
<?PHP echo wc_price( $order->get_item_total( $item,false,true ),array( 'currency' => $order->get_order_currency() ) ); ?>
</td>
<td class="td" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',sans-serif;">
<?PHP echo get_post_meta( get_the_ID(),'barcode',true ); ?>
<?PHP echo get_post_meta( get_the_ID(),'ISBN',true ); ?>
</td>
</tr>
<?PHP
if ( $show_purchase_note && $purchase_note ) {
?>
<tr>
<td colspan="2" style="text-align:<?PHP echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',sans-serif;">
<?PHP
echo wp_kses_post( wpautop( do_shortcode( $purchase_note ) ) );
?>
</td>
</tr>
<?PHP
}
?>
<?PHP endforeach; ?>
如何在 PHP 中获取正确的代码以在我的电子邮件中显示 ISBN
和 barcode
?
解决方法
要添加额外的列,请在电子邮件中使用来自 woocommerce-barcode-isbn 插件的 ISBN 和条形码。
应用以下内容:
在 emails/email-order-details.php 中(@version 3.7.0)
替换第 44 行
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Price','woocommerce' ); ?></th>
与
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Rek ut / Streckkod','woocommerce' ); ?></th>
<th class="td" scope="col" style="text-align:<?php echo esc_attr( $text_align ); ?>;"><?php esc_html_e( 'Price','woocommerce' ); ?></th>
和
在第 71 和 80 行替换
colspan="2"
与
colspan="3"
在 emails/email-order-items.php 中(@version 3.7.0)
替换第 85 - 87 行
<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',Helvetica,Roboto,Arial,sans-serif;">
<?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?>
</td>
与
<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',sans-serif;">
<?php echo $product->get_meta( 'barcode' ); ?>
<?php echo $product->get_meta( 'ISBN' ); ?>
</td>
<td class="td" style="text-align:<?php echo esc_attr( $text_align ); ?>; vertical-align:middle; font-family: 'Helvetica Neue',sans-serif;">
<?php echo wp_kses_post( $order->get_formatted_line_subtotal( $item ) ); ?>
</td>
这应该会给你想要的结果,你可以进一步调整输出以满足你的需要