Hi @el-terrible-bmw,
Ok I see what your requirement is. By default, the plugin will only save the payment method if the user is logged in. You still want to use that filter because you have to tell Stripe that the payment method can be attached in the future. But there is an additional step since you want to create a Stripe customer.
If the user is not logged in, you will need to create the customer in Stripe then attach the payment method. You need to use a WooCommerce action that is triggered after the payment is processed. Here is some example code:
add_action('woocommerce_pre_payment_complete, function($order_id){
$order = wc_get_order($order_id);
$payment_method = WC()->payment_gateways()->payment_gateways()[$order->get_paymen_method()];
// if the order has a customer ID, then a Stripe customer already exists to return
// if the payment method is not part of the Stripe plugin, return.
if($order->get_customer_id || !$payment_method instanceof WC_Payment_Gateway_Stripe){return;}
$result = \WC_Stripe_Customer_Manager::instance()->create_customer( WC()->customer );
if ( ! is_wp_error( $result ) ) {
$order->update_meta_data( \WC_Stripe_Constants::CUSTOMER_ID, $result->id );
$order->save();
// save the payment method.
$result = $payment_method->create_payment_method( $order->get_meta( \WC_Stripe_Constants::PAYMENT_METHOD_TOKEN ), $result->id );
}
});