How can I clean up the database after changing my Stripe account?

In order to properly link local data to the data in Stripe’s systems, our Stripe extension stores various identifiers (for customers, cards, and so on) in your database. However, that data is specific to a single Stripe account.

For that reason, if you’re replacing a previous Stripe account with a new one, a database cleanup may be required. If you do not perform this cleanup, purchases could fail.

Before proceeding with the cleanup, however, please contact Stripe to check whether the existing data can be transferred over to your new account. If it can, this procedure may not be necessary.

NOTE: We are unable to provide support for customizations under our Support Policy. If you need assistance with custom code, we highly recommend Codeable or a Certified WooExpert.

Cleaning up the database on a single site

↑ Back to top

This is an example SQL query you might run on a single site installation of WordPress. Replace the wp_ value with your site’s database table prefix.

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';

Cleaning up the database on a multisite

↑ Back to top

This is an example SQL query you might run on a single site installation of WordPress. Replace the wp_ value with your site’s database table prefix.

This is an example SQL query you might run on a multisite installation of WordPress. Replace wp_999_ with the site prefix (or wp_ if cleaning up the database for the main site of the network, as it does not use a number in the prefix).

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';
Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.