从Woocommerce订购单获取数组中的最后一个项目

问题描述 投票:0回答:1

我想包括在电子邮件的最后订货注意事项外出给客户。在它输出的所有订单的注释的那一刻,我怎么可以编辑这个的foreach只显示最后/最新订单的票子吗?

安装使用PHP 7.2,但最好我想它在所有版本的工作,我应该回落到5.6 PHP,我已经在我的测试网站之前使用

<h2><?php _e( 'Order Notes', 'woocommerce' ); ?></h2>

<?php
$args = array(
    'status' => 'approve',
    'post_id' => $order->id
);
$comments = get_comments($args);
foreach($comments as $comment) :
    echo $comment->comment_content . '<br />';
endforeach;
?>

因此,期望的结果会显示“订单状态从保持变更为完成”

enter image description here

php wordpress foreach php-7
1个回答
0
投票

你可以摆脱foreach语句和使用这样的end()功能:

$lastcomment = end($comments);
echo $lastcomment->comment_content . '<br />';
© www.soinside.com 2019 - 2024. All rights reserved.