Jack Daniels
Jack Daniels

Reputation: 31

Extend woocommerce plugin

I have wordpress child theme, and in it I can extend woocommerce by creating folder of following structure:

/wp-content/themes/theme-child/woocommerce/single-product/add-to-cart/*.php

But the problem is that I wan't to extend something located in

/wp-content/plugins/woocommerce-plugin/templates/single-product/add-to-cart/*.php

By first approach I can override woocommerce files, but how do I do it for woocommerce-plugin?

Upvotes: 3

Views: 821

Answers (2)

Skatox
Skatox

Reputation: 4284

You can do it by calling the wc_get_template hook, just tell where the files should be overriden:

add_filter('wc_get_template', 'plugin_wc_templates', 10, 5);
function plugin_wc_templates ($located, $template_name, $args, $template_path, $default_path) {
    $plugin_path = plugin_dir_path( __FILE__ );
    $newtpl = str_replace('woocommerce/templates', $plugin_path. '/templates', $located);
    if ( file_exists($newtpl) )
        return $newtpl;
    return $located;
}

Remember to print $plugin_path variable to make sure that path is being generating ok.

Upvotes: 0

LoicTheAztec
LoicTheAztec

Reputation: 253773

To override woocommerce templates without changing anything in woocommerce plugin folder, you need to copy entire templates folder (located in woocommerce plugin) to your active child theme folder and rename it woocommerce (see here). Like this the active woocommerce templates are now in your child theme folder and you can customize them…

Upvotes: 1

Related Questions