I need to override a parent theme file which is added in function.php like this:

if (class_exists('Woocommerce')) {
require_once( get_template_directory() . '/woocommerce/config.php');

A template override does not work. If I add config.php into the child theme here: mychild/woocommerce/config.php has no effect.

I can get my own config.php file to run from the child theme folder like this:

if (class_exists('Woocommerce')) {
include( get_stylesheet_directory() . '/woocommerce/config.php');

But I get all kinds of 'Cannot redeclare' errors, so clearly this is not an override, but just stacking the same file.

I have read everything I can find on this and am having no luck.

Is this even possible?

  • Actually there is a filter you can add template_directory to make get_template_directory() return path as for get_stylesheet_directory() BUT make sure the filter is applied only when needed (i.e overwriting config.php file).. – Samuel Elh May 19 '16 at 0:26
  • Are there any resources that guide you how to do this? – AJD May 19 '16 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.