Normally we can add WooCommerce files to the theme so that it will override the default WooCommerce files.

But I am developing a plugin which is having some extra feature to the WooCommerce page and I want it to override the theme's WooCommerce files with its own files.

For now, I am adding the modified code of my plugin to the theme itself for making it work. But I want those files to run directly from the plugin so that I don't need to add those files each time I change the theme.

My main concern is the single product page (both simple and variable product).

Any helpful tips?

  • edit your question to show the code you use in the template file (and which file ?).
    – Kaperto
    Aug 17, 2018 at 19:24

1 Answer 1


You can use the wc_get_template filter, which allows you to override the absolute filepath to a template just before it's included. For example, this overrides checkout/payment.php:

add_filter( 'wc_get_template', function ( $file, $name ) {
    if ( $name === 'checkout/payment.php' ) {
        // $file must be an absolute filepath

        // e.g. path relative to current file
        $file = __dir__ . '/templates/checkout/payment.php';

        // e.g. path relative to parent directory
        $file = dirname( __dir__ ) . '/templates/checkout/payment.php';

    return $file;
}, 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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