Stripe: Fixing customer errors

Note: This is a Developer level doc provided as guidance. We are unable to dispense advice or review code under our Support Policy.

Cleaning the database after account changes ↑ Back to top

Whenever the Stripe.com account keys (Publishable API Key and/or Secret API Key) get changed, a database cleanup might be required. The gateway stores various identifiers (customer, card, source, etc.) in order to link local objects with Stripe, but those objects are account-specific. If you do not perform this cleanup, the store might encounter failed purchases.

Before the cleanup ↑ Back to top

Before proceeding, please contact Stripe to check whether existing customers and payment methods can be transferred over to the new account.

Cleanup ↑ Back to top

DELETE FROM `wp_usermeta`
WHERE meta_key IN ( '_stripe_customer_id', '_stripe_source_id', '_stripe_card_id' );
DELETE tokenmeta FROM `wp_woocommerce_payment_tokenmeta` tokenmeta
INNER JOIN `wp_woocommerce_payment_tokens` ON `wp_woocommerce_payment_tokens`.`token_id` = tokenmeta.`payment_token_id`
WHERE `wp_woocommerce_payment_tokens`.`gateway_id` = 'stripe';
DELETE FROM `wp_woocommerce_payment_tokens` WHERE gateway_id='stripe';

Cleanup when using a WordPress Multisite ↑ Back to top

This snippet is similar but cleans up site-specific values as well.

Please use this snippet for each site in the network, which requires cleanup. Replace wp_999_ with the site prefix. NB: The main site of the network does not use a number in the prefix, so you need to simply use wp_ instead of wp_999_.

DELETE FROM `wp_usermeta`
WHERE meta_key IN ( '_stripe_customer_id', '_stripe_source_id', '_stripe_card_id', 'wp_999__stripe_customer_id' );
DELETE tokenmeta FROM `wp_999_woocommerce_payment_tokenmeta` tokenmeta
INNER JOIN `wp_999_woocommerce_payment_tokens` ON `wp_999_woocommerce_payment_tokens`.`token_id` = tokenmeta.`payment_token_id`
WHERE `wp_999_woocommerce_payment_tokens`.`gateway_id` = 'stripe';
DELETE FROM `wp_999_woocommerce_payment_tokens` WHERE gateway_id='stripe';

Conflicts between sites in a network (multisite) ↑ Back to top

Multisite setups are supported out of the box since version 4.3.2 of the gateway. However, if the gateway has been used on a simple site, which was later converted to a multisite network, you might experience No such customer errors, or errors with saved cards.

To fix those errors, use the following SQL snippet, and make sure to replace wp_ (single underscore) with your database table prefix:

UPDATE `wp_usermeta`
SET `meta_key` = CONCAT( 'wp_', `meta_key` )
WHERE `meta_key` IN ( '_stripe_customer_id', '_stripe_source_id', '_stripe_card_id' );

This will ensure that existing customer IDs from the main site/blog are not being used as fallback values for other sites.

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top