在 WooCommerce 的电子邮件中在 table 下方重复订购商品名称
Order item names repeating beneath table in emails in WooCommerce
我有一个挂钩到 woocommerce_order_item_name
的功能,目的是在商品名称下添加关于直销商品和延期交货商品的通知:
add_filter( 'woocommerce_order_item_name', 'custom_order_item_notices', 10, 2 );
function custom_order_item_notices( $item_name, $item ) {
if ( is_admin() )
return;
$echoed = false;
if ( is_cart() || is_checkout() || is_wc_endpoint_url( 'view-order' ) ) {
$backorder_qty = 0;
$product = $item->get_product();
$DID = strtoupper(get_post_meta($item['product_id'] , 'direct-dispatch', true));
if ($DID) {
switch ($DID) {
case 'BEE':
echo $item_name . '<small style="display: block;color: grey;">These items will be
sent directly from the supplier to your specified delivery address. Please allow 3-5 working days for
delivery. <a target="_blank" href="/delivery/#direct-despatch">Click here</a> for more info.</small>';
$echoed = true;
break;
}
}
if (get_post_meta($item->get_order_id(), 'split-order-type', true) == 'BKO') {
echo $item_name . '<small style="display: block;color: grey;">More stock is on it’s way! Please allow 5-10 working days for delivery. <a target="_blank" href="/delivery/#backorders">Click here</a> for more info.</small>';
$echoed = true;
}
}
if (!$echoed) echo $item_name;
}
我遇到了无法在显示订单项目的所有电子邮件模板中解释的问题。
问题是订单项名称在订单下方再次重复 table。
请看下图输出:
我的函数显然有问题导致了这个问题,但在尝试解决这个问题几个小时后,我仍然无法弄清楚输出来自哪里,所以任何帮助或将不胜感激。
您使用 echo
与 return
,我相信这会解决您的问题
function custom_order_item_notices( $item_name, $item ) {
if ( is_admin() )
return;
if ( is_cart() || is_checkout() || is_wc_endpoint_url( 'view-order' ) ) {
$backorder_qty = 0;
$product = $item->get_product();
$DID = strtoupper( get_post_meta($item['product_id'] , 'direct-dispatch', true) );
$DID = 'BEE';
if ( $DID ) {
switch ( $DID ) {
case 'BEE':
$item_name .= '<small style="display: block;color: grey;">These items will be sent directly from the supplier to your specified delivery address. Please allow 3-5 working days for delivery. <a target="_blank" href="/delivery/#direct-despatch">Click here</a> for more info.</small>';
break;
}
}
if ( get_post_meta( $item->get_order_id(), 'split-order-type', true) == 'BKO' ) {
$item_name .= '<small style="display: block;color: grey;">More stock is on it’s way! Please allow 5-10 working days for delivery. <a target="_blank" href="/delivery/#backorders">Click here</a> for more info.</small>';
}
}
return $item_name;
}
add_filter( 'woocommerce_order_item_name', 'custom_order_item_notices', 10, 2 );
我有一个挂钩到 woocommerce_order_item_name
的功能,目的是在商品名称下添加关于直销商品和延期交货商品的通知:
add_filter( 'woocommerce_order_item_name', 'custom_order_item_notices', 10, 2 );
function custom_order_item_notices( $item_name, $item ) {
if ( is_admin() )
return;
$echoed = false;
if ( is_cart() || is_checkout() || is_wc_endpoint_url( 'view-order' ) ) {
$backorder_qty = 0;
$product = $item->get_product();
$DID = strtoupper(get_post_meta($item['product_id'] , 'direct-dispatch', true));
if ($DID) {
switch ($DID) {
case 'BEE':
echo $item_name . '<small style="display: block;color: grey;">These items will be
sent directly from the supplier to your specified delivery address. Please allow 3-5 working days for
delivery. <a target="_blank" href="/delivery/#direct-despatch">Click here</a> for more info.</small>';
$echoed = true;
break;
}
}
if (get_post_meta($item->get_order_id(), 'split-order-type', true) == 'BKO') {
echo $item_name . '<small style="display: block;color: grey;">More stock is on it’s way! Please allow 5-10 working days for delivery. <a target="_blank" href="/delivery/#backorders">Click here</a> for more info.</small>';
$echoed = true;
}
}
if (!$echoed) echo $item_name;
}
我遇到了无法在显示订单项目的所有电子邮件模板中解释的问题。
问题是订单项名称在订单下方再次重复 table。
请看下图输出:
我的函数显然有问题导致了这个问题,但在尝试解决这个问题几个小时后,我仍然无法弄清楚输出来自哪里,所以任何帮助或将不胜感激。
您使用 echo
与 return
,我相信这会解决您的问题
function custom_order_item_notices( $item_name, $item ) {
if ( is_admin() )
return;
if ( is_cart() || is_checkout() || is_wc_endpoint_url( 'view-order' ) ) {
$backorder_qty = 0;
$product = $item->get_product();
$DID = strtoupper( get_post_meta($item['product_id'] , 'direct-dispatch', true) );
$DID = 'BEE';
if ( $DID ) {
switch ( $DID ) {
case 'BEE':
$item_name .= '<small style="display: block;color: grey;">These items will be sent directly from the supplier to your specified delivery address. Please allow 3-5 working days for delivery. <a target="_blank" href="/delivery/#direct-despatch">Click here</a> for more info.</small>';
break;
}
}
if ( get_post_meta( $item->get_order_id(), 'split-order-type', true) == 'BKO' ) {
$item_name .= '<small style="display: block;color: grey;">More stock is on it’s way! Please allow 5-10 working days for delivery. <a target="_blank" href="/delivery/#backorders">Click here</a> for more info.</small>';
}
}
return $item_name;
}
add_filter( 'woocommerce_order_item_name', 'custom_order_item_notices', 10, 2 );