The customer service is available through the WC_Payments_Customer_Service_API
class, available through WC_Payments::get_customer_service_api()
:
Example:
$payment_methods = WC_Payments::get_customer_service_api()->get_payment_methods_for_customer( 'cus_XXX', 'card' );
get_customer_id_by_user_id()
create_customer_for_user()
update_customer_for_user()
set_default_payment_method_for_customer()
get_payment_methods_for_customer()
update_payment_method_with_billing_details_from_order()
clear_cached_payment_methods_for_user()
map_customer_data()
delete_cached_payment_methods()
get_customer_id_for_order()
update_user_customer_id()
add_customer_id_to_user()
get_prepared_customer_data()
Get WCPay customer ID for the given WordPress user ID
Parameters
$user_id
(int
) The user ID to look for a customer ID with.
Return value
string?
WCPay customer ID or null if not found.
Create a customer and associate it with a WordPress user.
Parameters
$user
(WP_User
) User to create a customer for.$customer_data
(array
) Customer data.
Return value
string
The created customer's ID
Update the customer details held on the WCPay server associated with the given WordPress user.
Parameters
$customer_id
(string
) WCPay customer ID.$user
(WP_User
) WordPress user.$customer_data
(array
) Customer data. This should be the return value ofWC_Payments_Customer_Service_API::get_prepared_customer_data
below.
Return value
string
The updated customer's ID. Can be different to the ID parameter if the customer was re-created.
Sets a payment method as default for a customer.
Parameters
$customer_id
(string
) The customer ID.$payment_method_id
(string
) The payment method ID.
Gets all payment methods for a customer.
Parameters
$customer_id
(string
) The customer ID.$type
(string
) Type of payment methods to fetch.
Return value
array
Payment methods.
Updates a customer payment method.
Parameters
$payment_method_id
(string
) The payment method ID.$order
(WC_Order
) Order to be used on the update.
Return value
void
This method does not return any value.
Clear payment methods cache for a user.
Parameters
$user_id
(int
) WC user ID.
Return value
void
This method does not return any value.
Given a WC_Order or WC_Customer, returns an array representing a Stripe customer object.
At least one parameter has to not be null.
Parameters
$wc_order
(WC_Order
) The Woo order to parse.$wc_customer
(WC_Customer
) The Woo customer to parse.
Return value
array
Customer data.
public static function map_customer_data( WC_Order $wc_order, WC_Customer $wc_customer )
Delete all saved payment methods that are stored inside database cache driver.
Return value
void
This method does not return any value.
Get the WCPay customer ID associated with an order, or create one if none found.
Parameters
$order
(WC_Order
) WC Order object.
Return value
string|null
WCPay customer ID.
Updates the given user with the given WooCommerce Payments customer ID.
Parameters
$user_id
(int
) The WordPress user ID.$customer_id
(string
) The WooCommerce Payments customer ID.
Return value
void
This method does not return any value.
Adds the WooComerce Payments customer ID found in the user session to the WordPress user as metadata.
Parameters
$user_id
(int
) The WordPress user ID.
Return value
void
This method does not return any value.
Prepares customer data to be used on 'Pay for Order' or 'Add Payment Method' pages.
- Customer data is retrieved from order when on Pay for Order.
- Customer data is retrieved from customer when on 'Add Payment Method'.
Return value
array|null
An array with customer data or nothing.