melvin
melvin

Reputation: 2621

Plugin not taking default template

I want to override woocommerce email templates. So first it checks my defined template folder for templates. If it doesn't find any, then it should take template files from woocommerce folder. But my plugin is not taking from woocommerce folder. The problem is that checkout, shop etc templates are not loaded from woocommerce folder.

add_filter( 'woocommerce_locate_template', array( $this, 'woo_locate_template' ), 999, 3);

public function woo_locate_template($template,$template_name,$template_path){
        if(in_array($template_name, $this->templates)){
          return $this->get_email_template_path($template_name);
        }
}

public function get_email_template_path($template_name){
  $email_template_path = TH_WEC_EMAIL_TEMPLATE_PATH.$template;
  if(file_exists($email_template_path)){
    return $email_template_path;
  }
  return '';
}


public function init_template_name(){
    $this->templates = array(
        'emails/email-header.php',
        'emails/email-footer.php',
        'emails/email-styles.php',
        'emails/admin-new-order.php',
        'emails/admin-cancelled-order.php',
        'emails/admin-failed-order.php',
        'emails/customer-completed-order.php',
        'emails/customer-inovice.php',
        'emails/customer-new-account.php',
        'emails/customer-on-hold-order.php',
        'emails/customer-processing-order.php',
        'emails/customer-refunded-order.php',
        'emails/customer-reset-password.php',
    );
}

Upvotes: 0

Views: 86

Answers (2)

melvin
melvin

Reputation: 2621

The error was in not returning the default path. That is, $template

public function woo_locate_template($template,$template_name,$template_path){
    $_template = $template;
    if(in_array($template_name, $this->templates)){
        return $this->get_email_template_path($template_name);
    }
    return $_template;
}

Upvotes: 1

JudeAinsly
JudeAinsly

Reputation: 83

Easiest way is to move the templates into your active template directory. Path should be: Template root > woocommerce > emails

Then copy the files from Plugins > woocommerce > templates > emails , place in above folder and modify as you wish.

This way mail templates which are not in the theme directory will be fetched from the WC folder automatically.

Upvotes: 0

Related Questions