woocommerce - include customer-completed-order email template in plugin

Viewed 180

I try to override the woocommerce customer-completed-order.php template via a custom plugin I build. The most handy is to include the custom email template in the plugin, so various customers dont need to copy the template to a child theme.

So far i have (based upon internet research):

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

I tried to change the priority, by changing the priority to 9 instead of 20. However, that doesnt seem to help either.

Any help would be appriciated,

Kind regards, Kees

1 Answers

You should try this one:

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;
}

Note: You can change/update if ('customer-completed-order.php' === basename($template)) , cundition accordingly.

If now working above function, you can echo $template, $template_name, $template_path and update if() condition accordingly.

it's working 100% on my side.

Related