payment-methods.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.woocommerce.com/document/template-structure/
  16. * @author WooThemes
  17. * @package WooCommerce/Templates
  18. * @version 2.6.0
  19. */
  20. if ( ! defined( 'ABSPATH' ) ) {
  21. exit;
  22. }
  23. $saved_methods = wc_get_customer_saved_methods_list( get_current_user_id() );
  24. $has_methods = (bool) $saved_methods;
  25. $types = wc_get_account_payment_methods_types();
  26. do_action( 'woocommerce_before_account_payment_methods', $has_methods ); ?>
  27. <?php if ( $has_methods ) : ?>
  28. <table class="woocommerce-MyAccount-paymentMethods shop_table shop_table_responsive account-payment-methods-table">
  29. <thead>
  30. <tr>
  31. <?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
  32. <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>
  33. <?php endforeach; ?>
  34. </tr>
  35. </thead>
  36. <?php foreach ( $saved_methods as $type => $methods ) : ?>
  37. <?php foreach ( $methods as $method ) : ?>
  38. <tr class="payment-method<?php echo ! empty( $method['is_default'] ) ? ' default-payment-method' : '' ?>">
  39. <?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
  40. <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 ); ?>">
  41. <?php
  42. if ( has_action( 'woocommerce_account_payment_methods_column_' . $column_id ) ) {
  43. do_action( 'woocommerce_account_payment_methods_column_' . $column_id, $method );
  44. } elseif ( 'method' === $column_id ) {
  45. if ( ! empty( $method['method']['last4'] ) ) {
  46. /* translators: 1: credit card type 2: last 4 digits */
  47. echo sprintf( __( '%1$s ending in %2$s', 'woocommerce' ), esc_html( wc_get_credit_card_type_label( $method['method']['brand'] ) ), esc_html( $method['method']['last4'] ) );
  48. } else {
  49. echo esc_html( wc_get_credit_card_type_label( $method['method']['brand'] ) );
  50. }
  51. } elseif ( 'expires' === $column_id ) {
  52. echo esc_html( $method['expires'] );
  53. } elseif ( 'actions' === $column_id ) {
  54. foreach ( $method['actions'] as $key => $action ) {
  55. echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>&nbsp;';
  56. }
  57. }
  58. ?>
  59. </td>
  60. <?php endforeach; ?>
  61. </tr>
  62. <?php endforeach; ?>
  63. <?php endforeach; ?>
  64. </table>
  65. <?php else : ?>
  66. <p class="woocommerce-Message woocommerce-Message--info woocommerce-info"><?php esc_html_e( 'No saved methods found.', 'woocommerce' ); ?></p>
  67. <?php endif; ?>
  68. <?php do_action( 'woocommerce_after_account_payment_methods', $has_methods ); ?>
  69. <?php if ( WC()->payment_gateways->get_available_payment_gateways() ) : ?>
  70. <a class="button" href="<?php echo esc_url( wc_get_endpoint_url( 'add-payment-method' ) ); ?>"><?php esc_html_e( 'Add payment method', 'woocommerce' ); ?></a>
  71. <?php endif; ?>