我有一个与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;
}我有一个问题,我无法解释在所有的电子邮件模板显示订单项目。
问题是订单项名称在order表下再次重复。
请参阅以下输出图片:

很明显,我的功能出了点问题,但是经过几个小时的努力,我还是不知道输出是从哪里来的,所以我们会非常感谢你的帮助和见解。
发布于 2020-06-17 07:25:26
你使用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 );https://stackoverflow.com/questions/62416169
复制相似问题