Fixing 'Fatal error: Cannot redeclare class WC_Cart' and WordPress Plugin Conflicts

intermediate📝 WordPress2026-06-17| WordPress 5.0+, PHP 7.4/8.x, WooCommerce environment, Linux/Unix or Windows servers.

Error Message

Fatal error: Cannot redeclare class WC_Cart (previously declared in /wp-content/plugins/woocommerce/includes/class-wc-cart.php) in /wp-content/plugins/woocommerce/includes/class-wc-cart.php on line 1
#plugin-conflict#fatal-error#php#wordpress#class-redeclare

ContextSeeing a 'Cannot redeclare' error usually means your site has just crashed into the 'White Screen of Death' (WSOD). This happens because PHP hit a wall. It tried to load a class or function that already exists in the system's memory, and PHP doesn't allow duplicates.

The exact error message usually looks like this:

Fatal error: Cannot redeclare class WC_Cart (previously declared in /wp-content/plugins/woocommerce/includes/class-wc-cart.php) in /wp-content/plugins/woocommerce/includes/class-wc-cart.php on line 1

When the error points to the same file twice, like the WC_Cart example above, it is a bit of a riddle. It usually means the file was loaded through two different paths—often due to a symbolic link. It could also mean a rogue plugin is trying to 'mock' or override a core WooCommerce class improperly.

Debug ProcessSince you are likely locked out of your WordPress dashboard, grab your FTP credentials or open your hosting File Manager. You will need to dig into the files directly to see what is happening.

1. Enable WordPress DebuggingOpen your wp-config.php file in the root directory. Look for the line define( 'WP_DEBUG', false ); and replace it with these three lines:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );

This reveals the full file paths causing the clash. Often, you will find two different plugins trying to use the same common library, such as an outdated version of class-tgm-plugin-activation.php.

2. Spot the CulpritCheck the error message paths. If the paths are different, the second one mentioned is usually the plugin you just installed or updated. That is your 'culprit.' If the paths are identical, the code is likely using require instead of require_once.

Step-by-Step Solutions### Method 1: The 'Rename' ShortcutIf the crash happened right after a plugin update, use FTP to navigate to /wp-content/plugins/. Rename the suspect plugin's folder—for example, change jetpack to jetpack-off. This instantly deactivates the plugin. If your site suddenly breathes again, you have found the source.

Method 2: Switch to require_onceCustom code often triggers this error if you load the same file multiple times. Using require or include is risky in loops or complex themes. It is better to use the 'once' variants to tell PHP to skip the file if it is already loaded.

Avoid this:

require( plugin_dir_path( __FILE__ ) . 'includes/helpers.php' );

Use this instead:

require_once( plugin_dir_path( __FILE__ ) . 'includes/helpers.php' );

Method 3: Use Defensive Wrapper ChecksProfessional developers always check if a name is taken before using it. This simple 'if' statement prevents 99% of redeclaration errors in the WordPress ecosystem.

For Functions:

if ( ! function_exists( 'my_unique_prefix_utility' ) ) {
    function my_unique_prefix_utility() {
        // Code goes here
    }
}

For Classes:

if ( ! class_exists( 'My_Plugin_Handler' ) ) {
    class My_Plugin_Handler {
        // Code goes here
    }
}

Method 4: Fix WC_Cart Specific ConflictsThe WC_Cart error is notorious on sites using 'Must Use' plugins or heavy optimization scripts. Look inside /wp-content/mu-plugins/. If you find a script trying to start a session or call the cart before WooCommerce is fully ready, it will trigger this fatal crash. Delete or update these legacy scripts to fix the loop.

Verification- Refresh your homepage and /wp-admin/. Everything should load without a white screen.- Open /wp-content/debug.log. Check for any 'Notice' or 'Deprecated' messages that might hint at future conflicts.- Turn your plugins back on one by one. If the error returns when you activate a specific one, that plugin has a hardcoded conflict that needs a developer's fix.## Lessons Learned- Prefix Everything: Never name a function get_data(). Use a unique prefix like acme_get_data() to stay safe.- Adopt Namespaces: Modern PHP developers use namespace MyPlugin\Utilities;. This creates a private container for your code, making 'Cannot redeclare' errors almost impossible.- Watch Your Symlinks: Some hosts use symbolic links for shared libraries. PHP sometimes sees these as unique absolute paths, causing it to load the same file twice. Always use __FILE__ and dirname() carefully.

Related Error Notes