【发布时间】:2017-03-01 08:55:05
【问题描述】:
WooCommerce 提供了各种钩子和操作来更改预定义的模板。但我需要从订单电子邮件中隐藏收货地址并显示 N/A。我使用插件创建了一种自定义运输方式。使用该插件我必须更改地址。 任何帮助将不胜感激。
【问题讨论】:
标签: php wordpress woocommerce
WooCommerce 提供了各种钩子和操作来更改预定义的模板。但我需要从订单电子邮件中隐藏收货地址并显示 N/A。我使用插件创建了一种自定义运输方式。使用该插件我必须更改地址。 任何帮助将不胜感激。
【问题讨论】:
标签: php wordpress woocommerce
终于找到了解决办法:
function myplugin_plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
add_filter( 'woocommerce_locate_template', 'myplugin_woocommerce_locate_template', 10, 3 );
function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path ) $template_path = $woocommerce->template_url;
$plugin_path = myplugin_plugin_path() . '/woocommerce/';
$template = locate_template( array(
$template_path . $template_name,
$template_name));
// Modification: Get the template from this plugin, if it exists
if ( ! $template && file_exists( $plugin_path . $template_name ) )
$template = $plugin_path . $template_name;
// Use default template
if ( ! $template )
$template = $_template;
return $template;
}
普通的 WooCommerce 模板加载器按顺序搜索以下位置:
参考链接:https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/
【讨论】: