Flash sale: Get up to 30% off themes and extensions. Ends April 26 at 3 pm UTC. Shop the sale.
  1. Documentation /
  2. Stripe WooCommerce Extension /
  3. Customizing the Stripe WooCommerce Extension /
  4. How can I clean up the database after changing my Stripe account?

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

Whenever you connect a new Stripe account to your WooCommerce site, a database cleanup might be required.

The Stripe WooCommerce Extension stores various identifiers (e.g., customer, card, source, etc.) in a site’s database 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.

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

When you determine that changing Stripe accounts is a viable option, you can run an SQL query to prevent an increase in failed purchases due to misconfigured database values.

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 may run on a single site installation. Please 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 may run on a multisite installation. Please replace the wp_ value with your site’s database table prefix.

This is an example SQL query you may run on a subsite in a multisite network. Please 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';