Recent Orders on the My Account Dashboard
Lists the customer's three latest orders with status and total on the My Account dashboard, so they see what matters without clicking through.
Opens WPIDE on
Code
$wpide_recent_count = 3; // Orders to show.
add_action( 'woocommerce_account_dashboard', function () use ( $wpide_recent_count ) {
$orders = wc_get_orders( array(
'customer_id' => get_current_user_id(),
'limit' => $wpide_recent_count,
'orderby' => 'date',
'order' => 'DESC',
'status' => array_keys( wc_get_order_statuses() ),
) );
if ( ! $orders ) {
return;
}
echo '<h3>' . esc_html( 'Your recent orders' ) . '</h3><table class="woocommerce-orders-table shop_table shop_table_responsive"><thead><tr><th>' . esc_html( 'Order' ) . '</th><th>' . esc_html( 'Date' ) . '</th><th>' . esc_html( 'Status' ) . '</th><th>' . esc_html( 'Total' ) . '</th></tr></thead><tbody>';
foreach ( $orders as $order ) {
printf(
'<tr><td data-title="%1$s"><a href="%2$s">#%3$s</a></td><td data-title="%4$s">%5$s</td><td data-title="%6$s">%7$s</td><td data-title="%8$s">%9$s</td></tr>',
esc_attr( 'Order' ),
esc_url( $order->get_view_order_url() ),
esc_html( $order->get_order_number() ),
esc_attr( 'Date' ),
esc_html( wc_format_datetime( $order->get_date_created() ) ),
esc_attr( 'Status' ),
esc_html( wc_get_order_status_name( $order->get_status() ) ),
esc_attr( 'Total' ),
wp_kses_post( $order->get_formatted_order_total() )
);
}
echo '</tbody></table>';
} );
Notes
Change $wpide_recent_count to show more or fewer orders.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.