Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce向orderCompleted电子邮件添加订单注释_Php_Woocommerce - Fatal编程技术网

Php WooCommerce向orderCompleted电子邮件添加订单注释

Php WooCommerce向orderCompleted电子邮件添加订单注释,php,woocommerce,Php,Woocommerce,我在这里束手无策,已经在网上尝试了好几天我能找到的每一个解决方案,但都没有效果。最糟糕的是,这个问题应该在大约4行代码中就能解决,但它就是不起作用 我需要什么: 当订单完成电子邮件发出时,我希望将订单注释(不是客户注释,而是实际订单注释)添加到电子邮件中。之后我可以过滤它们,但我似乎根本无法让这些笔记出现在电子邮件中。这是订单上的订单注释…示例: 到目前为止,我已经尝试了以下代码: ::PHP:: <?php $comments = $order->get_customer_ord

我在这里束手无策,已经在网上尝试了好几天我能找到的每一个解决方案,但都没有效果。最糟糕的是,这个问题应该在大约4行代码中就能解决,但它就是不起作用

我需要什么: 当订单完成电子邮件发出时,我希望将订单注释(不是客户注释,而是实际订单注释)添加到电子邮件中。之后我可以过滤它们,但我似乎根本无法让这些笔记出现在电子邮件中。这是订单上的订单注释…示例:

到目前为止,我已经尝试了以下代码:

::PHP::

<?php
$comments = $order->get_customer_order_notes();
if($comments){
    echo '<h2>' . _e( 'Order Notes', 'woocommerce' ) . '</h2>';
    foreach($comments as $comment) {
        echo $comment->comment_content . '<br />';
    }
}
?>
add_action( 'woocommerce_email_order_meta', 'bl_add_order_notes_to_completed_email', 10 );

function bl_add_order_notes_to_completed_email() {
    global $woocommerce, $post;
    // If the order is not completed then don't continue.
//    if ( get_post_status( $post->ID ) != 'wc-completed' ){
//        return false;
//    }

    $args = array(
        'post_id' => $post->ID,
        'status'  => 'approve',
        'type'    => 'order_note'
    );

    // Fetch comments
    $notes = get_comments( $args );

    echo '<h2>' . _e( 'Order Notes', 'woocommerce' ) . '</h2>';
    echo '<ul class="order_notes" style="list-style:none; padding-left:0px;">';

    // Check that there are order notes
    if ( $notes ) {
        // Display each order note
        foreach( $notes as $note ) {
            ?>
            <li style="padding:0px -10px;">
                <div class="note_content" style="background:#d7cad2; padding:10px;">
                    <?php echo wpautop( wptexturize( $note->comment_content ) ); ?>
                </div>

                <p class="meta">
                    <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( 'added on %1$s at %2$s', 'woocommerce-customer-order-notes-completed-order-emails' ), date_i18n( wc_date_format(), strtotime( $note->comment_date ) ), date_i18n( wc_time_format(), strtotime( $note->comment_date ) ) ); ?></abbr>
                    <?php if ( $note->comment_author !== __( 'WooCommerce', 'woocommerce-customer-order-notes-completed-order-emails' ) ) printf( ' ' . __( 'by %s', 'woocommerce-customer-order-notes-completed-order-emails' ), $note->comment_author ); ?>
                </p>
            </li>
            <?php
        }
    }
    echo '</ul>';
}

这基本上是我所需要的,除了它的目标客户的订单注释,这是用户在下订单时添加到订单中的注释。比如:“我的狗会捡起我的包裹,他的名字很幸运”

我还写了一个lugin,以获取其他人的笔记,其基础是:

::PHP::

<?php
$comments = $order->get_customer_order_notes();
if($comments){
    echo '<h2>' . _e( 'Order Notes', 'woocommerce' ) . '</h2>';
    foreach($comments as $comment) {
        echo $comment->comment_content . '<br />';
    }
}
?>
add_action( 'woocommerce_email_order_meta', 'bl_add_order_notes_to_completed_email', 10 );

function bl_add_order_notes_to_completed_email() {
    global $woocommerce, $post;
    // If the order is not completed then don't continue.
//    if ( get_post_status( $post->ID ) != 'wc-completed' ){
//        return false;
//    }

    $args = array(
        'post_id' => $post->ID,
        'status'  => 'approve',
        'type'    => 'order_note'
    );

    // Fetch comments
    $notes = get_comments( $args );

    echo '<h2>' . _e( 'Order Notes', 'woocommerce' ) . '</h2>';
    echo '<ul class="order_notes" style="list-style:none; padding-left:0px;">';

    // Check that there are order notes
    if ( $notes ) {
        // Display each order note
        foreach( $notes as $note ) {
            ?>
            <li style="padding:0px -10px;">
                <div class="note_content" style="background:#d7cad2; padding:10px;">
                    <?php echo wpautop( wptexturize( $note->comment_content ) ); ?>
                </div>

                <p class="meta">
                    <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( 'added on %1$s at %2$s', 'woocommerce-customer-order-notes-completed-order-emails' ), date_i18n( wc_date_format(), strtotime( $note->comment_date ) ), date_i18n( wc_time_format(), strtotime( $note->comment_date ) ) ); ?></abbr>
                    <?php if ( $note->comment_author !== __( 'WooCommerce', 'woocommerce-customer-order-notes-completed-order-emails' ) ) printf( ' ' . __( 'by %s', 'woocommerce-customer-order-notes-completed-order-emails' ), $note->comment_author ); ?>
                </p>
            </li>
            <?php
        }
    }
    echo '</ul>';
}
add_action('woocommerce_email_order_meta','bl_add_order_notes_to_completed_email',10);
功能bl\u添加\u订单\u备注\u到\u完成的\u电子邮件(){
全球$woocmerce,$post;
//如果订单未完成,则不要继续。
//如果(获取发布状态($post->ID)!=“wc已完成”){
//返回false;
//    }
$args=数组(
'post_id'=>$post->id,
“状态”=>“批准”,
'类型'=>'订单注释'
);
//获取评论
$notes=获取注释($args);
回音“”。_e('Order Notes','woocommerce');
echo'
    ; //检查是否有订购单 若有(附注){ //显示每个订单注释 foreach($notes作为$note){ ?>

  • 在主题文件夹中创建一个名为woocommerce的文件夹。在此文件夹中,创建一个名为emails的新文件夹,并在此文件夹中从wp content/plugins/woocommerce/templates/emails中复制customer-completed-order.php。然后在第51行添加此代码片段:请参阅


    在主题文件夹中创建一个名为woocommerce的文件夹。在此文件夹中,创建一个名为emails的新文件夹,并在此文件夹中从wp content/plugins/woocommerce/templates/emails复制customer-completed-order.php。并在第51行添加此片段:请参阅


    我一直在尝试实现与Ecolis相同的目标,并找到了一种可能对其他用户有所帮助的解决方案。我只是想在电子邮件中回显订单通知。在我的子主题文件夹中的电子邮件模板中,我编写了以下代码:

    <?php echo wpautop( wptexturize( make_clickable( $customer_note ) ) );  ?>
    
    
    

    源代码-

    我一直在尝试实现与Ecolis相同的功能,并找到了一种可能帮助其他用户的解决方案。我只想将订单通知回送到电子邮件中。在我的子主题文件夹中的电子邮件模板中,我编写了以下代码:

    <?php echo wpautop( wptexturize( make_clickable( $customer_note ) ) );  ?>
    
    
    

    代码源-

    尝试将此代码添加到函数中。php:

    add_action('woocommerce_email_在_order_表之前,'wc_add_order_notes_至_completed_email',10,1);
    功能wc\u添加\u订单\u备注\u到\u已完成的\u电子邮件($order){
    如果($email->id=='customer\u completed\u order'){
    回显“”。uuuu('Order Notes','woocommerce');
    $order\u notes=$order->get\u customer\u order\u notes();
    foreach($order\u notes作为$order\u note){
    回显“”.$order\u note->注释内容。“”;
    }
    }
    }
    
    尝试将此代码添加到函数中。php:

    add_action('woocommerce_email_在_order_表之前,'wc_add_order_notes_至_completed_email',10,1);
    功能wc\u添加\u订单\u备注\u到\u已完成的\u电子邮件($order){
    如果($email->id=='customer\u completed\u order'){
    回显“”。uuuu('Order Notes','woocommerce');
    $order\u notes=$order->get\u customer\u order\u notes();
    foreach($order\u notes作为$order\u note){
    回显“”.$order\u note->注释内容。“”;
    }
    }
    }
    
    回答这个问题要晚得多;但总比没有回答好。我最后使用的代码是以下代码,它工作正常,至今仍在运行:

    ?>
    <h2><?php _e( 'Tracking ID', 'woocommerce' ); ?></h2>
    <?php 
    $comments =  $order->get_customer_order_notes();
    $customer_comments = $order->get_order_notes();
    
    foreach( $comments as $comment ){
        if ( strpos( $comment -> comment_content, "MyTracking" ) !== false ){
            echo $comment -> comment_content . '<br />';
        }
    }
    foreach( $customer_comments as $comment_2 ){
        if ( strpos( $comment_2 -> comment_content, "filterText" ) !== false ){
            echo $comment_2 -> comment_content . '<br />';
        }
    }
    
    ?>
    
    回答这个问题要晚得多,但总比不回答好。我最终使用的代码仍然有效,至今仍在运行,如下所示:

    ?>
    <h2><?php _e( 'Tracking ID', 'woocommerce' ); ?></h2>
    <?php 
    $comments =  $order->get_customer_order_notes();
    $customer_comments = $order->get_order_notes();
    
    foreach( $comments as $comment ){
        if ( strpos( $comment -> comment_content, "MyTracking" ) !== false ){
            echo $comment -> comment_content . '<br />';
        }
    }
    foreach( $customer_comments as $comment_2 ){
        if ( strpos( $comment_2 -> comment_content, "filterText" ) !== false ){
            echo $comment_2 -> comment_content . '<br />';
        }
    }
    
    ?>
    
    我无意中发现了这条老帖子,它在寻找一种方法,将客户在“订单备注”中的备注放在管理员收到的Woocommerce新订单电子邮件的结帐页面上

    上面@Martyn Gray发布的代码运行良好:

    echo wpautop( wptexturize( make_clickable( $customer_note ) ) );
    
    我将Woocommerce admin-new-order.php电子邮件模板复制到我的子主题中,并将其添加到现有代码“用户定义的附加内容”中

    这是原始代码:

    /**
    * Show user-defined additional content - this is set in each email's settings.
    */
    if ( $additional_content ) {
    echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
    }
    
    这是更新的代码:

    /**
     * Show user-defined additional content - this is set in each email's settings.
     */
    if ( $additional_content ) {
        echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
    echo wpautop( wptexturize( make_clickable( $customer_note ) ) );
    }
    
    客户注释现在出现在所有Woocommerce电子邮件中,包括新订单、发票等

    WP v5.6.2 WC v5.0.0


    希望这对后面的任何人都有帮助。

    我偶然发现了这条老帖子,想在管理员收到的Woocommerce新订单电子邮件的结帐页上添加客户在“订单备注”中的备注

    上面@Martyn Gray发布的代码运行良好:

    echo wpautop( wptexturize( make_clickable( $customer_note ) ) );
    
    我将Woocommerce admin-new-order.php电子邮件模板复制到我的子主题中,并将其添加到现有代码“用户定义的附加内容”中

    这是原始代码:

    /**
    * Show user-defined additional content - this is set in each email's settings.
    */
    if ( $additional_content ) {
    echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
    }
    
    这是更新的代码:

    /**
     * Show user-defined additional content - this is set in each email's settings.
     */
    if ( $additional_content ) {
        echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
    echo wpautop( wptexturize( make_clickable( $customer_note ) ) );
    }
    
    客户注释现在出现在所有Woocommerce电子邮件中,包括新订单、发票等

    WP v5.6.2 WC v5.0.0


    希望这对后面的任何人都有帮助。

    你有没有尝试过filter hook
    woocommerce\u email\u order\u meta\u fields
    ?一些参考资料,问题是我不需要输入和访问新数据;只需添加现有的订单注释da即可