Well, I could go find a nulled version of the WooCommerce Stripe & give you the snippet, but in theory, what you want to do, is pretty simple, you want to grab the same data that is used upon checkout, if the credit card is saved, then the next best thing is the Stripe CID ( Customer ID ).
- Take the WooCommerce Stripe Integration.
- Find the code that integrates with the Checkout to output the credit card list.
- You’ll find something related to the current user_id, same function /
class, you want to run in your own script to retrieve the credit
cards, and simply do an array_shift or something to take the first
one. - Charge the credit card. ? That’s pretty much it.
Based on how Stripe works, you’ll actually get in a “bit of trouble” because the WooCommerce integration does not use the native stripe subscriptions ( to my knowledge ), and you’ll actually have to emulate an fully fledged order in WooCommerce to have it done properly.
A different trick is to rely on the email address, and use the Stripe API to do a search for the CID.
Here’s a code sample I’m using to get all subscriptions registered in stripe ( not woocommerce ), the CID and a lot of “juicy” data is available there, simply do a var_dump( $customer )
in the loop and an exit.
$customer_search = \Stripe\Customer::all( [
'email' => $email_address,
'limit' => 200
] );
if( empty( $customer_search->data ) )
return [];
$response = [];
foreach( $customer_search->data as $customer ) {
if( !isset( $customer->subscriptions )
|| empty( $customer->subscriptions->data ) )
continue;
foreach( $customer->subscriptions->data as $subscription ) {
if( is_string( $status ) && $subscription->status != $status )
continue;
if( is_array( $status ) && !in_array( $subscription->status, $status ) )
continue;
$response[] = $subscription;
}
}
return $response;