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).
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 Commented Nov 21, 2018 at 13:03
1 Answer
Reset to default 0You 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' );