获得倒数第二个评论php woo commerce followup email

时间:2015-08-09 00:26:07

标签: php woocommerce

我发现这个方便的代码可以为已完成的电子邮件添加订单备注。我真的只想添加最后两个音符,如果可能的话。有人可以告诉我需要调整什么吗?

<?php
    add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email' );

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

        echo '<h2>' . __( 'Order Notes', 'woocommerce' ) . '</h2>';
        echo '<ul class="order_notes">';

        if ( $notes ) {
            foreach( $notes as $note ) {
              $note_classes = get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'note' ) : array( 'note' );
              ?>
              <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo implode( ' ', $note_classes ); ?>">
                <div class="note_content">
                  (<?php printf( __( 'added %s ago', 'woocommerce' ), human_time_diff( strtotime( $note->comment_date_gmt ), current_time( 'timestamp', 1 ) ) ); ?>) <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
                </div>
              </li>
              <?php
            }
        } else {
            echo '<li>' . __( 'There are no notes for this order yet.', 'woocommerce' ) . '</li>';
        }

        echo '</ul>';
    }
?>

1 个答案:

答案 0 :(得分:0)

您可以尝试使用array_slice

在foreach之后和之前

$notes = array_slice($notes, 0, 2);