admin管理员组文章数量:1387387
I use this code in in my plugin file. The content from the original orders.php file is gone that means the filter does work but my own file does not showing up.
I added this code in the plugin main file
<?php
define("PLUGIN_DIR_PATH", plugin_dir_path(__FILE__));
?>
and this code below in the plugin functions file.
The functions.php is located in pluginfolder/required/functions.php
<?php
add_filter( 'wc_get_template', 'q343_get_template', 10, 5 );
function q343_get_template( $located, $template_name, $args, $template_path, $default_path ) {
if ( 'myaccount/orders.php' == $template_name ) {
$located = PLUGIN_DIR_PATH . 'required/templates/orders.php';
}
return $located;
}
?>
The template that I will load is located in pluginfolder/required/templates/orders.php
I use this code in in my plugin file. The content from the original orders.php file is gone that means the filter does work but my own file does not showing up.
I added this code in the plugin main file
<?php
define("PLUGIN_DIR_PATH", plugin_dir_path(__FILE__));
?>
and this code below in the plugin functions file.
The functions.php is located in pluginfolder/required/functions.php
<?php
add_filter( 'wc_get_template', 'q343_get_template', 10, 5 );
function q343_get_template( $located, $template_name, $args, $template_path, $default_path ) {
if ( 'myaccount/orders.php' == $template_name ) {
$located = PLUGIN_DIR_PATH . 'required/templates/orders.php';
}
return $located;
}
?>
The template that I will load is located in pluginfolder/required/templates/orders.php
Share Improve this question edited Apr 13, 2020 at 17:37 Loek Lemmens asked Apr 13, 2020 at 11:51 Loek LemmensLoek Lemmens 12 bronze badges1 Answer
Reset to default 2plugin_dir_path( FILE ) will return the current directory. Not sure where you call this q343_get_template() function if it's on a subdirectory then plugin_dir_path( FILE ) is returning that subdirectory path.
From WordPress Code Reference https://developer.wordpress/reference/functions/plugin_dir_path/
The “plugin” part of the name is misleading – it can be used for any file, and will not return the directory of a plugin unless you call it within a file in the plugin’s base directory.
The safest way is to use define on your root plugin file.
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
Then call the function like this
add_filter( 'wc_get_template', 'q343_get_template', 10, 5 );
function q343_get_template( $located, $template_name, $args, $template_path, $default_path ) {
if ( 'myaccount/orders.php' == $template_name ) {
$located = MY_PLUGIN_PATH . 'required/templates/orders.php';
}
return $located;
}
本文标签: pluginswcgettemplate new template does not showing up
版权声明:本文标题:plugins - wc_get_template new template does not showing up 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744571546a2613370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论