【问题标题】:How to Add automatically notes into woocommerce single order page如何在 woocommerce 单笔订单页面中自动添加备注
【发布时间】:2015-11-21 21:40:19
【问题描述】:

我想在单个订单页面中自动添加一个“自定义注释”,其中包含所订购产品的一些详细信息(如类别)。

是否可以用function.php中的函数来做?

【问题讨论】:

    标签: php function woocommerce


    【解决方案1】:

    是的,这是可能的。您需要在当前主题的functions.php文件中添加以下代码。

        function wdm_my_custom_notes_on_single_order_page($order){
    
                    $category_array=array();
                    foreach( $order->get_items() as $item_id => $item ) {
                        $product_id=$item['product_id'];
                        $product_cats = wp_get_post_terms( $product_id, 'product_cat' );
                        foreach( $product_cats as $key => $value ){
                            if(!in_array($value->name,$category_array)){
                                    array_push($category_array,$value->name);
                            }
                        }
                    }
                    $note = '<b>Categories of products in this Order : </b>'.implode(' , ',$category_array);
    echo $note;
    $order->add_order_note( $note );
    
        }
    
        add_action( 'woocommerce_order_details_after_order_table', 'wdm_my_custom_notes_on_single_order_page',10,1 );
    

    输出:

    您可以自定义此功能以满足更多需求。

    【讨论】:

    • 非常感谢@WisdmLabs 的回复。您的代码似乎正确,但我希望将通知放在 woocommerce-order-notes div 中(在 WP 管理区域的单个订单详细信息页面内),而不是在订单电子邮件中。检查 img 以了解我的意思 [link] (manuelragazzini.it/domandestackoverflow/notesorder.png)
    猜你喜欢
    • 2021-10-28
    • 2018-08-09
    • 2018-07-17
    • 2022-01-20
    • 1970-01-01
    • 2018-07-12
    • 2018-10-19
    • 2018-12-31
    • 2015-04-24
    相关资源
    最近更新 更多