【发布时间】:2016-08-02 07:18:40
【问题描述】:
我在这里束手无策,已经尝试了几天我可以在网上找到的所有解决方案,但没有任何效果。最糟糕的是,这个问题应该可以用大约 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 />';
}
}
?>
这基本上是我所需要的,除了它针对customer_order_notes,这是用户在下订单时添加到订单中的cmets。比如:“我的狗会捡我的包裹,他的名字很幸运”
我还写了一个 lugin 来获取其他人的笔记,基础是这样的:
::PHP::
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>';
}
我真的不知道为什么这不起作用。看起来应该,但它什么也没做。
【问题讨论】:
-
问题是我不需要输入和访问新数据;只需将现有的订单备注数据添加到电子邮件中。我可以这样做,但会出现同样的问题:如何访问管理员订单备注?如果我能得到它们,其余的都是可以解决的;尚未找到将它们输入变量的方法
-
好吧,看看代码(woocommerce 的订单完成电子邮件),您想要实现的可能是默认功能。
-
如果您的问题还没有解决,也许Add Order Notes To WooCommerce Completed Order Email可以帮助您。
-
我从那篇文章开始,这只是我后来发现并构建自己的插件中的代码,以及我用来显示它们的其他 3 个来源。没有工作。解决后,我将发布解决方案;但是当你实现他的代码时,那篇文章是垃圾并且充满了php错误。
标签: php woocommerce