1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Downloads |
4
|
|
|
* |
5
|
|
|
* Shows downloads on the account page. |
6
|
|
|
* |
7
|
|
|
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/downloads.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
|
|
|
$downloads = WC()->customer->get_downloadable_products(); |
26
|
|
|
$has_downloads = (bool) $downloads; |
27
|
|
|
|
28
|
|
|
do_action( 'woocommerce_before_account_downloads', $has_downloads ); ?> |
29
|
|
|
|
30
|
|
|
<?php if ( $has_downloads ) : ?> |
31
|
|
|
|
32
|
|
|
<?php do_action( 'woocommerce_before_available_downloads' ); ?> |
33
|
|
|
|
34
|
|
|
<table class="woocommerce-MyAccount-downloads shop_table shop_table_responsive"> |
35
|
|
|
<thead> |
36
|
|
|
<tr> |
37
|
|
View Code Duplication |
<?php foreach ( wc_get_account_downloads_columns() as $column_id => $column_name ) : ?> |
|
|
|
|
38
|
|
|
<th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th> |
39
|
|
|
<?php endforeach; ?> |
40
|
|
|
</tr> |
41
|
|
|
</thead> |
42
|
|
|
<?php foreach ( $downloads as $download ) : ?> |
43
|
|
|
<tr> |
44
|
|
|
<?php foreach ( wc_get_account_downloads_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_account_downloads_column_' . $column_id ) ) : ?> |
47
|
|
|
<?php do_action( 'woocommerce_account_downloads_column_' . $column_id, $download ); ?> |
48
|
|
|
|
49
|
|
|
<?php elseif ( 'download-file' === $column_id ) : ?> |
50
|
|
|
<a href="<?php echo esc_url( get_permalink( $download['product_id'] ) ); ?>"> |
51
|
|
|
<?php echo esc_html( $download['download_name'] ); ?> |
52
|
|
|
</a> |
53
|
|
|
|
54
|
|
|
<?php elseif ( 'download-remaining' === $column_id ) : ?> |
55
|
|
|
<?php |
56
|
|
|
if ( is_numeric( $download['downloads_remaining'] ) ) { |
57
|
|
|
echo esc_html( $download['downloads_remaining'] ); |
58
|
|
|
} else { |
59
|
|
|
_e( '∞', 'woocommerce' ); |
60
|
|
|
} |
61
|
|
|
?> |
62
|
|
|
|
63
|
|
|
<?php elseif ( 'download-expires' === $column_id ) : ?> |
64
|
|
|
<?php if ( ! empty( $download['access_expires'] ) ) : ?> |
65
|
|
|
<time datetime="<?php echo date( 'Y-m-d', strtotime( $download['access_expires'] ) ); ?>" title="<?php echo esc_attr( strtotime( $download['access_expires'] ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $download['access_expires'] ) ); ?></time> |
66
|
|
|
<?php else : ?> |
67
|
|
|
<?php _e( 'Never', 'woocommerce' ); ?> |
68
|
|
|
<?php endif; ?> |
69
|
|
|
|
70
|
|
|
<?php elseif ( 'download-actions' === $column_id ) : ?> |
71
|
|
|
<?php |
72
|
|
|
$actions = array( |
73
|
|
|
'download' => array( |
74
|
|
|
'url' => $download['download_url'], |
75
|
|
|
'name' => __( 'Download', 'woocommerce' ) |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
if ( $actions = apply_filters( 'woocommerce_account_download_actions', $actions, $download ) ) { |
80
|
|
|
foreach ( $actions as $key => $action ) { |
81
|
|
|
echo '<a href="' . esc_url( $action['url'] ) . '" class="button woocommerce-Button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>'; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
?> |
85
|
|
|
|
86
|
|
|
<?php endif; ?> |
87
|
|
|
</td> |
88
|
|
|
<?php endforeach; ?> |
89
|
|
|
</tr> |
90
|
|
|
<?php endforeach; ?> |
91
|
|
|
</table> |
92
|
|
|
|
93
|
|
|
<?php do_action( 'woocommerce_after_available_downloads' ); ?> |
94
|
|
|
|
95
|
|
View Code Duplication |
<?php else : ?> |
|
|
|
|
96
|
|
|
<div class="woocommerce-Message woocommerce-Message--info woocommerce-info"> |
97
|
|
|
<a class="woocommerce-Button button" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>"> |
98
|
|
|
<?php esc_html_e( 'Go Shop', 'woocommerce' ) ?> |
99
|
|
|
</a> |
100
|
|
|
<?php esc_html_e( 'No downloads available yet.', 'woocommerce' ); ?> |
101
|
|
|
</div> |
102
|
|
|
<?php endif; ?> |
103
|
|
|
|
104
|
|
|
<?php do_action( 'woocommerce_after_account_downloads', $has_downloads ); ?> |
105
|
|
|
|
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.