I'm having trouble passing a Stripe Customer ID directly to a WC_Order object. I have tried passing it through the payment gateway metadata via the set_payment_method function however nothing I try seems to work.
I am trying to complete an entire order programmatically in order to migrate another system over to WordPress. We're trying to do this with WC Subscription objects which inherit from WC_Order.
Let me know if there is a good solution to this. Thank you!
Here's a bit of code to demonstrate what I'm basically trying to do:
$order = wc_create_order(['customer_id' => $user_id]);
$user = get_user_by( 'ID', $user_id );
$order->add_product( $product, 1 );
$payment_gateways = WC()->payment_gateways->payment_gateways();
$order->set_payment_method($payment_gateways['stripe'], [
'customer_id' => 'cus_XXXXXXXXXXXXXX' // this part right here, doesnt seem to work
]);
// $order->set_payment_method($payment_gateways['stripe'], [
// 'stripe_customer_id' => 'cus_XXXXXXXXXXXXXX' // also doesnt seem to work
// ]);
The ending result was that the order could not be completed and transactions do not come through to our Stripe account either.
Documentation on the set_payment_method function is very limited and provides no additional information on supported data that can be passed.