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?
$email_actions[] = 'woocommerce_order_status_shipped;
instead of the transition. Though I think the real deal-killer is that you aren't passing a new instance of the class here$email_classes['WC_Expedited_Order_Email']
you are passing the included file. Include the file on the line above and then instantiate the class. See this tutorial – helgathevikingecho "something"
beforedie()
? – JazZ