Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • I did use the filter, and my case was very similar to him I think. But it still doesn’t work. My code below (similar to above):

    add_filter( 'wc_stripe_force_save_payment_method', '__return_true', 10, 3 );
    
    add_action('woocommerce_pre_payment_complete', 'create_customer_in_stripe', 10, 1 );
    function create_customer_in_stripe ($order_id) {
    	$order = wc_get_order($order_id);
    	$payment_method = WC()->payment_gateways()->payment_gateways()[$order->get_payment_method()];
    
    	// if the order has a customer ID, then a Stripe customer already exists to return
    	if ($order->get_customer_id) {
    		return;
    	}
    
    	// If order is not using Stripe CC payment method, do not create a customer
    	if ($order->get_payment_method() != 'stripe_cc') {
    		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 );
    	}
    }

    Hi,

    I use this code snippet to force saved cards for rental purpose and it keeps adding on the same card to the customer’s account whenever they login and make a purchase. So one customer may have 5 cards ending in 4042 underneath their saved cards after making 5 purchases used their saved cards. Is there a way to fix this?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)