0

I want to display my custom template for Single Product i.e. single-product.php

For WordPress native templates, we can use add_filter( 'single_template', 'custom_single_tmpl' ); and a callback function looks like this:

    public function custom_single_tmpl( $tempalte ) {
       return PLUG_DIR_PATH . '/templates/custom-single.php';
    }

Is there any way to override WooCommerce template files like that?

Edit: I want to override Header and Footer as well, not only a single product content (same way as WordPress above add_filter does).

1
  • Can anyone explain why this question gets downvoted? Or comments removed on it?
    – Duke
    Commented Nov 21, 2018 at 13:03

1 Answer 1

0

You would use my answer from this post to change the template: Redirect woocommerce single-product page

Then you could use the following functions in your functions.php file to change the header and footer only on that template:

function themeslug_footer_hook( $name ) {
    if ( get_page_template() == "Your Page Template"  ) { 
        <!-- New Footer Content -->
    }
}
add_action( 'get_footer', 'themeslug_footer_hook' );

function themeslug_header_hook( $name ) {
    if ( get_page_template() == "Your Page Template"  ) { 
        <!-- New Header Content -->
    }
}
add_action( 'get_header', 'themeslug_header_hook' );
2
  • Mate, FROM PLUGIN not from the theme. What's wrong with my question, nobody understands it...
    – Duke
    Commented Nov 22, 2018 at 6:24
  • The function names don't matter. This will work in a plugin without an issue.
    – Fencer04
    Commented Nov 22, 2018 at 22:24

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.