1

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.

WC Subscriptions API Reference

mujuonly
  • 11,370
  • 5
  • 45
  • 75
Toxxy
  • 13
  • 3

1 Answers1

0

The payment meta array can consist of 3 keys and their values. They are inserted into 3 tables as mentioned in the below example.

$payment_meta = array(
    'user_meta' => array(
        'payment_usermeta_key' => 'Test payment user meta value',
        'customer_id', 'cus_XXXXXXXXXXXXXX'
    ),
    'post_meta' => array(
        'payment_post_meta_key' => 'Test payment post meta value'
    ),
    'options' => array(
        'payment_related_options_key' => 'Test payment options value'
    )
)
mujuonly
  • 11,370
  • 5
  • 45
  • 75