woocommerce - 在插件中包含客户完成订单电子邮件模板
woocommerce - include customer-completed-order email template in plugin
我尝试通过我构建的自定义插件覆盖 woocommerce customer-completed-order.php 模板。
最方便的是在插件中包含自定义邮件模板,这样各种客户就不需要将模板复制到子主题中了。
到目前为止我有(基于互联网研究):
function intercept_wc_template( $template, $template_name, $template_path ) {
if ( strpos($template_name,'customer-completed-order.php' ) ) {
$template = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'template/woocommerce/customer-completed-order.php';
}
return $template;
}
add_filter('woocommerce_locate_template', 'intercept_wc_template', 20, 3);
我试图通过将优先级更改为 9 而不是 20 来更改优先级。但是,这似乎也无济于事。
如有任何帮助,我们将不胜感激,
谨致问候,基斯
你应该试试这个:
add_filter('woocommerce_locate_template', 'woo_customer_completed_order_template', 10, 4);
function woo_customer_completed_order_template($template, $template_name, $template_path)
{
if ('customer-completed-order.php' === basename($template)){
$template = trailingslashit(plugin_dir_path( __FILE__ )) . 'templates/woocommerce/customer-completed-order.php';
}
return $template;
}
注意:您可以 change/update if ('customer-completed-order.php' === basename($template)) ,相应地调整。
如果现在在上述函数上运行,您可以回显 $template、$template_name、$template_path 并相应地更新 if() 条件。
我这边 100% 有效。
我尝试通过我构建的自定义插件覆盖 woocommerce customer-completed-order.php 模板。 最方便的是在插件中包含自定义邮件模板,这样各种客户就不需要将模板复制到子主题中了。
到目前为止我有(基于互联网研究):
function intercept_wc_template( $template, $template_name, $template_path ) {
if ( strpos($template_name,'customer-completed-order.php' ) ) {
$template = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'template/woocommerce/customer-completed-order.php';
}
return $template;
}
add_filter('woocommerce_locate_template', 'intercept_wc_template', 20, 3);
我试图通过将优先级更改为 9 而不是 20 来更改优先级。但是,这似乎也无济于事。
如有任何帮助,我们将不胜感激,
谨致问候,基斯
你应该试试这个:
add_filter('woocommerce_locate_template', 'woo_customer_completed_order_template', 10, 4);
function woo_customer_completed_order_template($template, $template_name, $template_path)
{
if ('customer-completed-order.php' === basename($template)){
$template = trailingslashit(plugin_dir_path( __FILE__ )) . 'templates/woocommerce/customer-completed-order.php';
}
return $template;
}
注意:您可以 change/update if ('customer-completed-order.php' === basename($template)) ,相应地调整。
如果现在在上述函数上运行,您可以回显 $template、$template_name、$template_path 并相应地更新 if() 条件。
我这边 100% 有效。