1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Payment methods |
4
|
|
|
* |
5
|
|
|
* Shows customer payment methods on the account page. |
6
|
|
|
* |
7
|
|
|
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/payment-methods.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
|
|
|
$saved_methods = wc_get_customer_saved_methods_list( get_current_user_id() ); |
26
|
|
|
$has_methods = (bool) $saved_methods; |
27
|
|
|
$types = wc_get_account_payment_methods_types(); |
28
|
|
|
|
29
|
|
|
do_action( 'woocommerce_before_account_payment_methods', $has_methods ); ?> |
30
|
|
|
|
31
|
|
|
<?php if ( $has_methods ) : ?> |
32
|
|
|
|
33
|
|
|
<table class="woocommerce-MyAccount-paymentMethods shop_table shop_table_responsive account-payment-methods-table"> |
34
|
|
|
<thead> |
35
|
|
|
<tr> |
36
|
|
View Code Duplication |
<?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?> |
|
|
|
|
37
|
|
|
<th class="woocommerce-PaymentMethod woocommerce-PaymentMethod--<?php echo esc_attr( $column_id ); ?> payment-method-<?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
|
|
|
<?php foreach ( $saved_methods as $type => $methods ) : ?> |
42
|
|
|
<?php foreach ( $methods as $method ) : ?> |
43
|
|
|
<tr class="payment-method<?php echo ! empty( $method['is_default'] ) ? ' default-payment-method' : '' ?>"> |
44
|
|
|
<?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?> |
45
|
|
|
<td class="woocommerce-PaymentMethod woocommerce-PaymentMethod--<?php echo esc_attr( $column_id ); ?> payment-method-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>"> |
46
|
|
|
<?php |
47
|
|
|
if ( has_action( 'woocommerce_account_payment_methods_column_' . $column_id ) ) { |
48
|
|
|
do_action( 'woocommerce_account_payment_methods_column_' . $column_id, $method ); |
49
|
|
|
} else if ( 'method' === $column_id ) { |
50
|
|
|
if ( ! empty ( $method['method']['last4'] ) ) { |
51
|
|
|
echo sprintf( __( '%s ending in %s', 'woocommerce' ), esc_html( wc_get_credit_card_type_label( $method['method']['brand'] ) ), esc_html( $method['method']['last4'] ) ); |
52
|
|
|
} else { |
53
|
|
|
echo esc_html( wc_get_credit_card_type_label( $method['method']['brand'] ) ); |
54
|
|
|
} |
55
|
|
|
} else if ( 'expires' === $column_id ) { |
56
|
|
|
echo esc_html( $method['expires'] ); |
57
|
|
|
} else if ( 'actions' === $column_id ) { |
58
|
|
|
foreach ( $method['actions'] as $key => $action ) { |
59
|
|
|
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a> '; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
?> |
63
|
|
|
</td> |
64
|
|
|
<?php endforeach; ?> |
65
|
|
|
</tr> |
66
|
|
|
<?php endforeach; ?> |
67
|
|
|
<?php endforeach; ?> |
68
|
|
|
</table> |
69
|
|
|
|
70
|
|
|
<?php else : ?> |
71
|
|
|
|
72
|
|
|
<p class="woocommerce-Message woocommerce-Message--info woocommerce-info"><?php esc_html_e( 'No saved methods found.', 'woocommerce' ); ?></p> |
73
|
|
|
|
74
|
|
|
<?php endif; ?> |
75
|
|
|
|
76
|
|
|
<?php do_action( 'woocommerce_after_account_payment_methods', $has_methods ); ?> |
77
|
|
|
|
78
|
|
|
<a class="button" href="<?php echo esc_url( wc_get_endpoint_url( 'add-payment-method' ) ); ?>"><?php esc_html_e( 'Add Payment Method', 'woocommerce' ); ?></a> |
79
|
|
|
|
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.