phpwordpressemailwoocommercesendinblue

use php to change which woocommerce email template is used (NOT Customising templates)


I've been presented with a problem from SendInBlue, the email marketing provider.

To cut a long story short, SendInBlue only allows you to map the default woocommerce emails to the templates created in their software.

The problem I have is we use three custom templates which I cannot map.

One solution I thought maybe viable would be to create a function that changes my custom email use the woocommerce new order template which would in turn then be mapped to the SendInBlue new order template.

Is this something that's possible? if anyone is able to offer any input to this problem it would be greatly appreciated.

Thanks

.

ADDITIONAL

Im using the SendinBlue Woocommerce plugin - https://wordpress.org/plugins/woocommerce-sendinblue-newsletter-subscription/

This is a screenshot of the admin page where you map your Woocommerce email to the SendinBlue template https://ps.w.org/woocommerce-sendinblue-newsletter-subscription/trunk/screenshot-3.png?rev=1745315


Solution

  • WooCommerce uses the wc_locate_template filter to load their templates.

    You can use this filter to conditionally load specific templates or return the default. This will not answer your question specifically, but will give you a general direction of how to solve this problem.

    I ran into a similar problem trying to use blade templates in my WP theme when using WooCommerce.

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