Posted on

WooCommerce: Disable Theme’s WooCommerce Template Overrides

A client purchased a premium “WooCommerce-ready” WordPress theme on Themeforest. Unfortunately, this theme comes with a /woocommerce folder, which means theme developers completely override WooCommerce template files by copying them to the folder, and customizing each of them by hand to match their design and functionality needs.

As you know from my “How To Become an Advanced WooCommerce Developer?” article, however, themes should NOT come with a /woocommerce folder – instead they should use “hooks” (actions and filters) to amend default WooCommerce plugin layouts and behavior. This is a huge problem for best seller themes and their legacy coding – and also a reason most themes break when you update WooCommerce…

So the question I asked myself was: how can I disable the entire /woocommerce folder (i.e. ALL WooCommerce template overrides) in a given theme, so that I can use the default WooCommerce ones instead?

Fix 1 (not ideal): Disable Theme’s /woocommerce Folder

The easiest thing to do is going to your theme’s folder inside wp-content and RENAME the /woocommerce folder to something else e.g. /DISABLED-woocommerce (see screenshot above)

Super easy – but next time you update the theme, you’d need to re-do this. And trust me, you’ll probably forget about it and your WooCommerce site will use those overrides once again…

Fix 2 (ideal): Add a Single Line to wp-config.php File

This is a little gem (thanks to Damien Carbery who came to my rescue). If you study WooCommerce plugin files, and specifically the wc_get_template_part() function, you will see a note:

WC_TEMPLATE_DEBUG_MODE will prevent overrides in themes from taking priority

So, thanks to Damien, I added the following line to wp-config.php:


/**
* @snippet Do not load theme /woocommerce folder - WooCommerce
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=80903
* @author Rodolfo Melogli
* @compatible WooCommerce 3.4.7
*/

// Add this to wp-config.php file

define( 'WC_TEMPLATE_DEBUG_MODE', true );

 

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

4 thoughts on “WooCommerce: Disable Theme’s WooCommerce Template Overrides

  1. Hey Rodolfo,
    What’s the point of preventing overrides in themes from taking priority altogether ?
    You always need to override emails at least.
    When I develop a theme, the Woocommerce folder is a must I think.
    Also, if you disable it in commercial theme you bought you harm the theme function.
    Could you refer to these issues?

    1. These are very good questions Yehuda, thanks!

      You always need to override emails at least” – not entirely true. WooCommerce email hooks are usually sufficient, also Woo are launching a new email template editor very soon.

      When I develop a theme, the WooCommerce folder is a must I think” – definitely not, I don’t like themes that do that (hence this tutorial). Actions and filters can make you achieve 99% of the customization you usually require. Storefront theme has no /woocommerce folder for example.

      Also, if you disable it in commercial theme you bought you harm the theme function” – yep, definitely possible, depending on how the theme is coded. Mostly if they also have woocommerce.php file override and other weird things. In general, themes should use WooCommerce hooks and not any other way for overriding WooCommerce.

      Hope this makes sense 🙂

  2. Hello, Rodolfo,

    I added the code but the notifications are not gone http://prntscr.com/l9vuwx

    1. Hey Christian, thanks for your comment 🙂 I don’t think this function also removed those override notifications – but for sure it does avoid those overrides are loaded. Just tried on a client’s website, works very well!

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.