Retrieve payment method history for WooCommerce customers
P粉745412116
P粉745412116 2024-04-04 14:57:11
0
1
533

I found a script that helps me get the information I need: the payment methods the customer has historically used on orders.

$order = new WC_Order( $order_id );
$payment_title = $order->get_payment_method_title();`

Unfortunately, I don't know where to start with this information. Where should I post this string so that it does my expected output?

I want to export this to a .csv file so it can be imported into a spreadsheet.

Everything I've found so far seems to assume I already know where to start. I'm just looking for a simple pointer on where to start.

P粉745412116
P粉745412116

reply all(1)
P粉835428659

To get the customer history payment gateway you need:

  • Get customers first
  • Get each customer’s order
  • Display payment list for these orders

Try the following:

// Get customers IDs
$customers_ids = get_users( array(
    'role__in' => array('customer'),
    'number' => 10,  // First 10 customers
    // 'offset' => 0,
) );
echo '
'. print_r( count($customers_ids), true ) . '
'; // Loop through customers foreach ( $customers_ids as $user ) { echo'

User ID: '.$user->ID. ' - User email: '.$user->user_email.'

'; // Get the order paid by the customer $customer_orders = wc_get_orders( array( 'Limit' => -1, 'Customer' => $user->ID, 'Status' => wc_get_is_paid_statuses(), ) ); echo '
    '; // Loop order foreach( $customer_orders as $order ) { printf('
  • Order: #%s - Date: %s - Payment: %s
  • ', $order->get_id(), $order->get_date_created()->format('Y-m-d'), $order->get_ payment_method_title() ); } echo'
'; }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template