1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Orders |
4
|
|
|
* |
5
|
|
|
* Shows orders on the account page. |
6
|
|
|
* |
7
|
|
|
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/orders.php. |
8
|
|
|
* |
9
|
|
|
* HOWEVER, on occasion WooCommerce will need to update template files and you |
10
|
|
|
* (the theme developer) will need to copy the new files to your theme to |
11
|
|
|
* maintain compatibility. We try to do this as little as possible, but it does |
12
|
|
|
* happen. When this occurs the version of the template file will be bumped and |
13
|
|
|
* the readme will list any important changes. |
14
|
|
|
* |
15
|
|
|
* @see https://docs.woothemes.com/document/template-structure/ |
16
|
|
|
* @author WooThemes |
17
|
|
|
* @package WooCommerce/Templates |
18
|
|
|
* @version 2.6.0 |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
22
|
|
|
exit; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
do_action( 'woocommerce_before_account_orders', $has_orders ); ?> |
26
|
|
|
|
27
|
|
|
<?php if ( $has_orders ) : ?> |
28
|
|
|
|
29
|
|
|
<table class="woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table"> |
30
|
|
|
<thead> |
31
|
|
|
<tr> |
32
|
|
View Code Duplication |
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?> |
|
|
|
|
33
|
|
|
<th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th> |
34
|
|
|
<?php endforeach; ?> |
35
|
|
|
</tr> |
36
|
|
|
</thead> |
37
|
|
|
|
38
|
|
|
<tbody> |
39
|
|
View Code Duplication |
<?php foreach ( $customer_orders->orders as $customer_order ) : |
|
|
|
|
40
|
|
|
$order = wc_get_order( $customer_order ); |
41
|
|
|
$item_count = $order->get_item_count(); |
42
|
|
|
?> |
43
|
|
|
<tr class="order"> |
44
|
|
|
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?> |
45
|
|
|
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>"> |
46
|
|
|
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?> |
47
|
|
|
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?> |
48
|
|
|
|
49
|
|
|
<?php elseif ( 'order-number' === $column_id ) : ?> |
50
|
|
|
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>"> |
51
|
|
|
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?> |
52
|
|
|
</a> |
53
|
|
|
|
54
|
|
|
<?php elseif ( 'order-date' === $column_id ) : ?> |
55
|
|
|
<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> |
56
|
|
|
|
57
|
|
|
<?php elseif ( 'order-status' === $column_id ) : ?> |
58
|
|
|
<?php echo wc_get_order_status_name( $order->get_status() ); ?> |
59
|
|
|
|
60
|
|
|
<?php elseif ( 'order-total' === $column_id ) : ?> |
61
|
|
|
<?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?> |
62
|
|
|
|
63
|
|
|
<?php elseif ( 'order-actions' === $column_id ) : ?> |
64
|
|
|
<?php |
65
|
|
|
$actions = array( |
66
|
|
|
'pay' => array( |
67
|
|
|
'url' => $order->get_checkout_payment_url(), |
68
|
|
|
'name' => __( 'Pay', 'woocommerce' ) |
69
|
|
|
), |
70
|
|
|
'view' => array( |
71
|
|
|
'url' => $order->get_view_order_url(), |
72
|
|
|
'name' => __( 'View', 'woocommerce' ) |
73
|
|
|
), |
74
|
|
|
'cancel' => array( |
75
|
|
|
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ), |
76
|
|
|
'name' => __( 'Cancel', 'woocommerce' ) |
77
|
|
|
) |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
if ( ! $order->needs_payment() ) { |
81
|
|
|
unset( $actions['pay'] ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) { |
85
|
|
|
unset( $actions['cancel'] ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ( $actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order ) ) { |
89
|
|
|
foreach ( $actions as $key => $action ) { |
90
|
|
|
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>'; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
?> |
94
|
|
|
<?php endif; ?> |
95
|
|
|
</td> |
96
|
|
|
<?php endforeach; ?> |
97
|
|
|
</tr> |
98
|
|
|
<?php endforeach; ?> |
99
|
|
|
</tbody> |
100
|
|
|
</table> |
101
|
|
|
|
102
|
|
|
<?php do_action( 'woocommerce_before_account_orders_pagination' ); ?> |
103
|
|
|
|
104
|
|
|
<?php if ( 1 < $customer_orders->max_num_pages ) : ?> |
105
|
|
|
<div class="woocommerce-Pagination"> |
106
|
|
|
<?php if ( 1 !== $current_page ) : ?> |
107
|
|
|
<a class="woocommerce-Button woocommerce-Button--previous button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page - 1 ) ); ?>"><?php _e( 'Previous', 'woocommerce' ); ?></a> |
108
|
|
|
<?php endif; ?> |
109
|
|
|
|
110
|
|
|
<?php if ( $current_page !== intval( $customer_orders->max_num_pages ) ) : ?> |
111
|
|
|
<a class="woocommerce-Button woocommerce-Button--next button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page + 1 ) ); ?>"><?php _e( 'Next', 'woocommerce' ); ?></a> |
112
|
|
|
<?php endif; ?> |
113
|
|
|
</div> |
114
|
|
|
<?php endif; ?> |
115
|
|
|
|
116
|
|
View Code Duplication |
<?php else : ?> |
|
|
|
|
117
|
|
|
<div class="woocommerce-Message woocommerce-Message--info woocommerce-info"> |
118
|
|
|
<a class="woocommerce-Button button" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>"> |
119
|
|
|
<?php _e( 'Go Shop', 'woocommerce' ) ?> |
120
|
|
|
</a> |
121
|
|
|
<?php _e( 'No order has been made yet.', 'woocommerce' ); ?> |
122
|
|
|
</div> |
123
|
|
|
<?php endif; ?> |
124
|
|
|
|
125
|
|
|
<?php do_action( 'woocommerce_after_account_orders', $has_orders ); ?> |
126
|
|
|
|
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.