首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WooCommerce中的电子邮件中重复下面的订单项目名称

在WooCommerce中的电子邮件中重复下面的订单项目名称
EN

Stack Overflow用户
提问于 2020-06-16 19:27:35
回答 1查看 70关注 0票数 3

我有一个与woocommerce_order_item_name挂钩的函数,用于在项目名称下添加下拉项目和回序项的通知:

代码语言:javascript
复制
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表下再次重复。

请参阅以下输出图片:

很明显,我的功能出了点问题,但是经过几个小时的努力,我还是不知道输出是从哪里来的,所以我们会非常感谢你的帮助和见解。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-17 07:25:26

你使用echoreturn,我相信这会解决你的问题

代码语言:javascript
复制
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 );
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62416169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档