【问题标题】:Extract URL from order note and add it only to order completed email in Woocommerce从订单备注中提取 URL 并将其仅添加到 Woocommerce 中已完成的订单电子邮件
【发布时间】:2017-02-24 10:08:57
【问题描述】:

我在这里搜索过,一些帖子帮助我几乎解决了这个问题:

我的包裹公司在订单中添加了订单备注,其中包括包裹的文本和跟踪网址。然后他们将订单完成。

此 URL 需要添加到给客户的订单完成邮件中。

此代码有效,但前提是我手动发送订单完成邮件:

add_action( 'woocommerce_email_before_order_table', 'woo_add_order_notes_to_email' );
function woo_add_order_notes_to_email() {
    global $woocommerce, $post;
    $args = array(
        'post_id'   => $post->ID,
        'status'    => 'approve',
        'type'      => 'order_note'
    );
    $notes = get_comments( $args );

    if ( $notes ) {
        foreach( $notes as $note ) {
            $notecontent = $note->comment_content;

            if( preg_match('/[a-zA-Z]+:\/\/[0-9a-zA-Z;.\/?:@=_#&%~,+$-]+/', $notecontent, $matches) != 0 ) {

                echo '<p>You can follow your order via this link: <a href = "' . $matches[0] . '">' . $matches[0] . '</a></p>';

            }
        }
    }
}

希望大家能帮帮我。

【问题讨论】:

    标签: php wordpress email woocommerce


    【解决方案1】:

    我认为你使用了错误的钩子。

    你可以用这个钩子“woocommerce_email_order_meta”做同样的事情。它将解决您的问题。

    这里是代码示例

    add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email' );
    
    function woo_add_order_notes_to_email( $order, $sent_to_admin = false, $plain_text = false ) {
      /*Do something here to add with order completion email */ 
    }
    

    【讨论】:

    • 嗨 Nishad,感谢您的评论,但这只会将注释的位置更改为订单元部分(在表格下方)。
    猜你喜欢
    • 2016-08-02
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多