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粉8354286592024-04-05 00:54:59
To get the customer history payment gateway you need:
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'