php - 在 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;
}
我遇到了一个无法在所有显示订单项目的电子邮件模板中解释的问题。
问题是订单项目名称在订单表下方再次重复。
请看下面的输出图像:
我的函数显然有问题导致了这种情况,但是在尝试解决这个问题几个小时后,我什至仍然无法弄清楚输出的来源,所以任何帮助或见解将不胜感激.
解决方案
你使用echo
vs 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 );
推荐阅读
- openshift - Openshift 中 nginx ui 服务的控制台日志以 Zulu 时间戳编写 - 希望它们在 EST 中
- flutter - 如何获取 Flutter App 中使用的包版本
- c# - 如何保持属性同步
- php - 如何在wordpress自定义帖子上设置帖子数量
- download - GIT repo 下载但不结帐
- python - Django - 案例为假时过滤
- c# - Sustainsys.Saml2 在普通 Asp.Net Core MVC Web 应用程序中的集成
- c++ - 如何重写我的宏以与 IDE 自动格式配合使用?
- java - 应用程序因使用 com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch 而崩溃
- spacy - 我可以使用 Spacy 进行名词分类吗?