wc_get_account_saved_payment_methods_list

Returns an array of a user's saved payments list for output on the account tab.

Description

(array) wc_get_account_saved_payment_methods_list( (array) $list, (int) $customer_id ); 

Returns (array)

Filtered list of customers payment methods

Parameters (2)

0. $list (array)
List of payment methods passed from wc_get_customer_saved_methods_list()
1. $customer_id (int)
The customer to fetch payment methods for

Usage

  1. if ( !function_exists( 'wc_get_account_saved_payment_methods_list' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-account-functions.php'; 
  3.  
  4. // List of payment methods passed from wc_get_customer_saved_methods_list() 
  5. $list = array(); 
  6.  
  7. // The customer to fetch payment methods for 
  8. $customer_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_get_account_saved_payment_methods_list($list, $customer_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-account-functions.php  
  1. function wc_get_account_saved_payment_methods_list( $list, $customer_id ) { 
  2. $payment_tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id ); 
  3. foreach ( $payment_tokens as $payment_token ) { 
  4. $delete_url = wc_get_endpoint_url( 'delete-payment-method', $payment_token->get_id() ); 
  5. $delete_url = wp_nonce_url( $delete_url, 'delete-payment-method-' . $payment_token->get_id() ); 
  6. $set_default_url = wc_get_endpoint_url( 'set-default-payment-method', $payment_token->get_id() ); 
  7. $set_default_url = wp_nonce_url( $set_default_url, 'set-default-payment-method-' . $payment_token->get_id() ); 
  8.  
  9. $type = strtolower( $payment_token->get_type() ); 
  10. $list[ $type ][] = array( 
  11. 'method' => array( 
  12. 'gateway' => $payment_token->get_gateway_id(),  
  13. ),  
  14. 'expires' => esc_html__( 'N/A', woocommerce ),  
  15. 'is_default' => $payment_token->is_default(),  
  16. 'actions' => array( 
  17. 'delete' => array( 
  18. 'url' => $delete_url,  
  19. 'name' => esc_html__( 'Delete', woocommerce ),  
  20. ),  
  21. ),  
  22. ); 
  23. $key = key( array_slice( $list[ $type ], -1, 1, true ) ); 
  24.  
  25. if ( ! $payment_token->is_default() ) { 
  26. $list[ $type ][ $key ]['actions']['default'] = array( 
  27. 'url' => $set_default_url,  
  28. 'name' => esc_html__( 'Make default', woocommerce ),  
  29. ); 
  30.  
  31. $list[ $type ][ $key ] = apply_filters( 'woocommerce_payment_methods_list_item', $list[ $type ][ $key ], $payment_token ); 
  32. return $list;