首页 > 解决方案 > 使用 php 更改使用的 woocommerce 电子邮件模板(不自定义模板)

问题描述

电子邮件营销提供商 SendInBlue 向我提出了一个问题。

长话短说,SendInBlue 只允许您将默认的 woocommerce 电子邮件映射到他们的软件中创建的模板。

我遇到的问题是我们使用了三个无法映射的自定义模板。

我认为可能可行的一种解决方案是创建一个更改我的自定义电子邮件的函数,使用 woocommerce 新订单模板,然后将其映射到 SendInBlue 新订单模板。

这是可能的吗?如果有人能够对此问题提供任何意见,将不胜感激。

谢谢

.

额外的

我正在使用 SendinBlue Woocommerce 插件 - https://wordpress.org/plugins/woocommerce-sendinblue-newsletter-subscription/

这是您将 Woocommerce 电子邮件映射到 SendinBlue 模板的管理页面的屏幕截图https://ps.w.org/woocommerce-sendinblue-newsletter-subscription/trunk/screenshot-3.png?rev=1745315

标签: phpwordpressemailwoocommercesendinblue

解决方案


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

推荐阅读