简体   繁体   中英

How do I replace the OOTB woo customer completed order email?

In a plugin I'm working on, I'm trying to replace the OOTB customer-completed-order email with a template in the plugin

Constructor:

define( 'BKF_WC_EMAIL_PATH', plugin_dir_path( __FILE__ ) );
add_filter('wc_get_template', array($this, 'bkf_customer_completed_order_template'), PHP_INT_MAX, 5);

Function:

    function bkf_customer_completed_order_template($template, $template_name, $args, $template_path, $default_path) {
        if( $template_name == 'emails/customer-completed-order.php' ) {
            $template = trailingslashit(BKF_WC_EMAIL_PATH) . 'templates/' . $template_name;
            return $template;
        }
    }

note the template is still pulling the default woo one

Any thoughts/ideas are welcome!

Worked it out!

Instead of the method used in my original question, here's what worked for me:

I created a new class (similar to woocommerce/includes/emails/class-wc-email-customer-completed-order.php) - for demo purposes we'll call it My_Custom_Class

I then called like so in my constructor for the parent class I was working on:

add_action('woocommerce_email_classes', array( $this, 'bk_register_email' ), PHP_INT_MAX, 1 );

And added this function:

public function bk_register_email( $emails ) {
        require_once 'emails/my-custom-class.php';

        $emails['WC_Email_Customer_Completed_Order'] = new My_Custom_Class();

        return $emails;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM