As Featured In Fatstacks

Solving WooCommerce 404 Error on Product Pages & More

Published Categorised as Amazon FBA

WooCommerce 404 errors can be common, especially when your plugin stack gets even mildly complex. One of the most common reasons for the 404 error is a failed automatic update or corrupt edit of the .htaccess file.

Reasons for the WooCommerce 404 Error

  1. A corrupt .htaccess file caused by a plugin, WooCommerce or WordPress itself
  2. You’ve added a category or attribute with the base ‘/product/’ which is in conflict with WooCommerce Product Permalink settings

Solving a Corrupt .htacess File Causing WooCommerce 404 Error – Short Term

Many WooCommerce and WordPress plugins add code to the .htaccess file and interact with the code placed within it.

Your WordPress Caching Plugin will be adding caching directives…

Your WordPress Security Plugin will be adding security protocols, whitelisted IPs etc…

Your core WooCommerce settings will be adding directives for permalink structures etc…

There’s a whole list

The great news is there’s a VERY simple fix to the WooCommerce 404 error when it’s caused by a corrupt .htaccess file.

If you can still login to the backend of WordPress:

  1. Head to Settings > Permalinks
  2. Click “Save” at the bottom of the page (no need to change anything)
  3. Flush the Cache for good measure
  4. Verify the fix has worked in incognito / from a different Wifi connection

If you can’t login to the backend of WordPress:

  1. Head over to your host and login
  2. Go to the “file manager” section (exact location will differ depending on which WooCommerce Host you’re using)
  3. Make a copy of the .htaccess file
  4. Rename the old .htaccess file to something like .htaccess1
  5. Copy and paste a default WordPress .htaccess file from here into your new .htaccess file
  6. Save the new .htaccess file
  7. Flush the cache from the hosting dashboard (if you can)
  8. Verify the fix has worked in incognito / from a different Wifi connection

Solving a Corrupt .htaccess File Causing WooCommerce 404 Problem – Long Term

As the solution basically involves “Clicking Save” on the Permalinks settings page inside WordPress, this is definitely something that can be automated.

So…

All you need to do is add a cron job to flush the .htaccess file frequently to limit the time for which the error can actually occurr.

What the hell is a cron job you say?

Don’t panic – all you ACTUALLY need to do is add a code snippet using the “Code Snippets” plugin and click “Save and Activate” and you’re DONE. NO Code knowledge necessary – it’s child’s play.

Here’s the code you need to add:

// Flush permalinks every hour 
add_action('my_hourly_event', 'do_this_hourly');
 
function my_activation() {
    if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
        wp_schedule_event(time(), 'hourly', 'my_hourly_event');
    }
}
 
add_action('wp', 'my_activation');
 
function do_this_hourly() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

Full credit for this code, and original source is isitwp.com – see the original code here

And here’s the code snippets plugin if you’ve not already got it installed:

Solving A Clash With A Category Or Attribute URL Base Causing WooCommerce 404 Error

As you’ll see on this drawn out thread on Github – this is more of a common caused of a WooCommerce 404 problem than I’d EVER have anticipated.

It basically means that an admin level user has intentionally created a “Post Category” or “Product Attribute” with the name “Product” – this means the slug for that category or attribute includes /product/ which is ALSO the default slug (permalink) for Product pages in WooCommerce.

This naturally leads to a conflict and means you’ve got a “human error” cause – and the technology hasn’t prevented that human error from occurring. Sometimes (a lot of the time) software just isn’t “poka yoke” and human error mistakes are allowed by the software when they shouldn’t be.

At some point in the future – this may well change and this error will become impossible – but for now, just watch out for rogue store owners and clients who could be causing some head scratching for you, the website manager!

By Ashley Pearce

I'm the founder of Future State Media, a "small-on-purpose" creator-focused SEO agency skilled in helping creators systematically generate traffic, build audiences and maximise their monetisation whilst staying true to their brand.