I am just now learning WordPress theming as I have time.

Currently I have a bunch of overrides for many woocommerce defaults in my theme I have:

// CUSTOM FUNCTIONS
require get_template_directory() . '/woocommerce/storefunctions/woocommerce-overrides.php';

Is there a way to do this that is more portable? Such as if I want to change themes how can I avoid adding in the functions.php file for every theme I want to try/fiddle with. I don't know what to search for, so the question: what have I tried is: nothing.

up vote 2 down vote accepted

I'd say that the thing you're looking for is having functions.php as a plugin. This makes it portable, regardless of the theme you are using. The most simple way is create a new file (something like my-woocommerce-functions.php) and start with the following:

<?php
/**
 * Plugin Name: My Custom WooCommerce Functions
 * Plugin URI: http://example.com
 * Description: My Custom WooCommerce Functions
 * Author: Your Name
 * Author URI: http://example.com
 * Version: 1.0.0
 */

/* Place custom code below this line. */
require get_template_directory() . '/woocommerce/storefunctions/woocommerce-overrides.php';
?>

Now you have a plugin which you can activate and deactivate from dashboard. You would have to take care about file paths only (if not using get_template_directory() function).

  • you just improved my life tons! I made the plugin and also found a way to use the same plugin to use my own woocommerce/path-to-same/name-of-template.php file so I can add my own freaking slider and touch ready lightbox. The stuff they had was 2009 old. Thanks again! – Christina Oct 14 '15 at 20:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.