$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Override WooCommerce files from plugin|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Override WooCommerce files from plugin

matteradmin8PV0评论

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' );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far