qhaensler
qhaensler

Reputation: 11

Add custom emails Woocommerce

I've a plugin for manage my shipments with two custom status : awaiting-shipment and shipped.

I try to add an email sent when the order passes to shipped.

I find this on Stack Overflow : Woocommerce Refund Email but I can figure how it's work

Here is my plugin file code :
I updated my code with the recommendations of helgatheviking and Adrien Leber below

function shippement_tracking_filter_actions( $actions ){
    $actions[] = "woocommerce_order_status_shipped";
    return $actions;
}
add_filter( 'woocommerce_email_actions', 'shippement_tracking_filter_actions' );

function add_expedited_order_woocommerce_email( $email_classes ) {
    require( 'includes/class-wc-expedited-order-email.php' );
    $email_classes['WC_Expedited_Order_Email'] = new WC_Expedited_Order_Email();
    return $email_classes;
}
add_filter( 'woocommerce_email_classes', 'add_expedited_order_woocommerce_email' );`

And my Class :

class WC_Expedited_Order_Email extends WC_Email {
    public function __construct() {

        $this->id               = 'expedited_order_tracking';
        $this->customer_email   = true;
        $this->title            = __( 'Shippement Traking', 'customEmail' );
        $this->description      = __( 'Sent tracking email to customer', 'customEmail' );
        $this->heading          = __( 'Your {site_title} order is shipped', 'customEmail' );
        $this->subject          = __( 'Your {site_title} order from {order_date} is shipped', 'customEmail' );

        $this->template_html    = 'emails/customer-order_tracking.php';
        $this->template_plain   = 'emails/plain/customer-order_tracking.php';

        add_action( 'woocommerce_order_status_shipped', array( $this, 'trigger' ) );

        parent::__construct();
    }

    public function trigger( $order_id )
    {
        var_dump($order_id);die();
    }

When I change my order status, nothing happens! My trigger function is never call.

Can anyone help me?

Upvotes: 1

Views: 1709

Answers (1)

JazZ
JazZ

Reputation: 4579

I think you misunderstood this part :

function add_expedited_order_woocommerce_email( $email_classes ) {
   $email_classes['WC_Expedited_Order_Email'] = include( plugin_dir_path( __FILE__ ) . '/class-wc-expedited-order-email.php' );
   return $email_classes;
}

You have to include the class file first and then create a new instance of this class :

function add_expedited_order_woocommerce_email( $email_classes ) {

    // include our custom email class
    require( 'includes/class-wc-expedited-order-email.php' );

    // add the email class to the list of email classes that WooCommerce loads
    $email_classes['WC_Expedited_Order_Email'] = new WC_Expedited_Order_Email();

    return $email_classes;

}

Hope it helps.

Upvotes: 1

Related Questions