1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* My Orders |
4
|
|
|
* |
5
|
|
|
* @deprecated 2.6.0 this template file is no longer used. My Account shortcode uses orders.php. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
9
|
|
|
exit; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
$my_orders_columns = apply_filters( 'woocommerce_my_account_my_orders_columns', array( |
13
|
|
|
'order-number' => __( 'Order', 'woocommerce' ), |
14
|
|
|
'order-date' => __( 'Date', 'woocommerce' ), |
15
|
|
|
'order-status' => __( 'Status', 'woocommerce' ), |
16
|
|
|
'order-total' => __( 'Total', 'woocommerce' ), |
17
|
|
|
'order-actions' => ' ', |
18
|
|
|
) ); |
19
|
|
|
|
20
|
|
|
$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array( |
21
|
|
|
'numberposts' => $order_count, |
22
|
|
|
'meta_key' => '_customer_user', |
23
|
|
|
'meta_value' => get_current_user_id(), |
24
|
|
|
'post_type' => wc_get_order_types( 'view-orders' ), |
25
|
|
|
'post_status' => array_keys( wc_get_order_statuses() ) |
26
|
|
|
) ) ); |
27
|
|
|
|
28
|
|
|
if ( $customer_orders ) : ?> |
29
|
|
|
|
30
|
|
|
<h2><?php echo apply_filters( 'woocommerce_my_account_my_orders_title', __( 'Recent Orders', 'woocommerce' ) ); ?></h2> |
31
|
|
|
|
32
|
|
|
<table class="shop_table shop_table_responsive my_account_orders"> |
33
|
|
|
|
34
|
|
|
<thead> |
35
|
|
|
<tr> |
36
|
|
|
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?> |
37
|
|
|
<th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th> |
38
|
|
|
<?php endforeach; ?> |
39
|
|
|
</tr> |
40
|
|
|
</thead> |
41
|
|
|
|
42
|
|
|
<tbody> |
43
|
|
View Code Duplication |
<?php foreach ( $customer_orders as $customer_order ) : |
|
|
|
|
44
|
|
|
$order = wc_get_order( $customer_order ); |
45
|
|
|
$item_count = $order->get_item_count(); |
46
|
|
|
?> |
47
|
|
|
<tr class="order"> |
48
|
|
|
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?> |
49
|
|
|
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>"> |
50
|
|
|
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?> |
51
|
|
|
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?> |
52
|
|
|
|
53
|
|
|
<?php elseif ( 'order-number' === $column_id ) : ?> |
54
|
|
|
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>"> |
55
|
|
|
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?> |
56
|
|
|
</a> |
57
|
|
|
|
58
|
|
|
<?php elseif ( 'order-date' === $column_id ) : ?> |
59
|
|
|
<time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time> |
60
|
|
|
|
61
|
|
|
<?php elseif ( 'order-status' === $column_id ) : ?> |
62
|
|
|
<?php echo wc_get_order_status_name( $order->get_status() ); ?> |
63
|
|
|
|
64
|
|
|
<?php elseif ( 'order-total' === $column_id ) : ?> |
65
|
|
|
<?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?> |
66
|
|
|
|
67
|
|
|
<?php elseif ( 'order-actions' === $column_id ) : ?> |
68
|
|
|
<?php |
69
|
|
|
$actions = array( |
70
|
|
|
'pay' => array( |
71
|
|
|
'url' => $order->get_checkout_payment_url(), |
72
|
|
|
'name' => __( 'Pay', 'woocommerce' ) |
73
|
|
|
), |
74
|
|
|
'view' => array( |
75
|
|
|
'url' => $order->get_view_order_url(), |
76
|
|
|
'name' => __( 'View', 'woocommerce' ) |
77
|
|
|
), |
78
|
|
|
'cancel' => array( |
79
|
|
|
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ), |
80
|
|
|
'name' => __( 'Cancel', 'woocommerce' ) |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
if ( ! $order->needs_payment() ) { |
85
|
|
|
unset( $actions['pay'] ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) { |
89
|
|
|
unset( $actions['cancel'] ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ( $actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order ) ) { |
93
|
|
|
foreach ( $actions as $key => $action ) { |
94
|
|
|
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>'; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
?> |
98
|
|
|
<?php endif; ?> |
99
|
|
|
</td> |
100
|
|
|
<?php endforeach; ?> |
101
|
|
|
</tr> |
102
|
|
|
<?php endforeach; ?> |
103
|
|
|
</tbody> |
104
|
|
|
</table> |
105
|
|
|
<?php endif; ?> |
106
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.