admin管理员组

文章数量:1130349

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

Share Improve this question edited Nov 21, 2018 at 12:21 Duke asked Nov 21, 2018 at 10:52 DukeDuke 133 bronze badges 1
  • Can anyone explain why this question gets downvoted? Or comments removed on it? – Duke Commented Nov 21, 2018 at 13:03
Add a comment  | 

1 Answer 1

Reset to default 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' );

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

Share Improve this question edited Nov 21, 2018 at 12:21 Duke asked Nov 21, 2018 at 10:52 DukeDuke 133 bronze badges 1
  • Can anyone explain why this question gets downvoted? Or comments removed on it? – Duke Commented Nov 21, 2018 at 13:03
Add a comment  | 

1 Answer 1

Reset to default 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' );

本文标签: Override WooCommerce files from plugin