WooCommerce 使用wc_locate_template过滤器来加载他们的模板。
您可以使用此过滤器有条件地加载特定模板或返回默认值。这不会具体回答您的问题,但会为您提供如何解决此问题的大致方向。
我在使用 WooCommerce 时尝试在我的 WP 主题中使用刀片模板时遇到了类似的问题。
/**
* Conditionally filter the email template WooCommerce chooses.
*
* @filter wc_locate_template
* @param {string} $template Full file path to original woo template
* @return {string} Full path to desired template to render
*/
function filter_wc_email_templates($template) {
// Psuedo code
$target = 'order-confirmation.php';
$replacement = 'shipping-confirmation.php';
$isTargetFile = strstr($template, $target) !== false;
if (! $isTargetFile) {
// if this is not the file we want to modify functionality for
// just retrun the default one
return $template;
} else {
// if this is the target file we want to replace
// return the full path to the file of the template we want to use
return getThemeTemplatePath() . '/<path to WooCommerce in your theme>/' . $replacement;
}
});
add_filter('wc_locate_template', 'filter_wc_email_templates');