-1

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).

  • Can anyone explain why this question gets downvoted? Or comments removed on it? – Duke Nov 21 '18 at 13:03
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' );
  • Mate, FROM PLUGIN not from the theme. What's wrong with my question, nobody understands it... – Duke Nov 22 '18 at 6:24
  • The function names don't matter. This will work in a plugin without an issue. – Fencer04 Nov 22 '18 at 22:24

Your Answer

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

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