从Woocommerce的订购单中获取阵列中的最后一项

时间:2019-02-02 18:46:05

标签: php wordpress foreach php-7

我想包括在电子邮件的最后订货注意事项外出给客户。目前,它输出所有的订购单,如何编辑此foreach以仅显示最新/最新的订购单?

该安装使用PHP 7.2,但理想情况下,如果我回到测试站点上以前使用的PHP 5.6,我希望它可以在所有版本中使用

<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

1 个答案:

答案 0 :(得分:0)

您可以摆脱foreach语句,并使用$a = array("654345","665456","566676"); $b = array("filename_654345.jpg", "filename-file_566676.jpg"); 功能是这样的:

end()