• Resolved mom4i911024

    (@mom4i911024)


    Hey there,
    I was wondering if it’s possible to attach the cancellation invoice PDF to a custom email linked to a custom order status created by the plugin WooCommerce Order Status Manager by SkyVerge? I want to include it there instead of sending a separate email only with the cancellation invoice. I tried using the following filter storeabill_woo_attach_invoice_cancellation_refund_to_email, but it seems in the source code there is a check to see if the email is for a refunded or a partially refunded order and only then it executes. Would my best bet in this case be to try and modify the template for the sab_cancellation_invoice instead of trying to attach the invoice cancellation PDF to some other email?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author vendidero

    (@vendidero)

    Hi there,

    please keep in mind that a cancellation is created for many other occasions too, e.g.:

    • When a refund is created
    • When an order is marked as cancelled
    • When an order is marked as fully refunded (in case necessary)
    • When finding a inconsistency within the order data (e.g. order item data has changed)
    • When manually cancelling an invoice

    If you wanted to cancel an invoice in case a custom order status has been chosen, you’ll need to hook into the status event and manually cancel the invoice. After that, you may trigger/attach the cancellation by using the woocommerce_email_attachments filter and check whether the current email instance equals the instance for which the cancellation should be attached.

    PS: Please use our help desk on support for our pro version.

    Best,
    Dennis

    Thread Starter mom4i911024

    (@mom4i911024)

    Got it, thank you! I’ve used this code, not sure if it’s the best approach but it seems to work fine for me.

    
    use Vendidero\StoreaBill\WooCommerce\Helper;
    
    add_filter('woocommerce_email_attachments', function ($attachments, $email_id, $object, $email) {
    	
    	//WooCommerce Order Status Manager email ID
    	if ( $email_id === 'wc_order_status_email_54059' ) {
    		if (is_a($object, 'WC_Order') && $order = Helper::get_order($object)) {
    			\Vendidero\StoreaBill\WooCommerce\Automation::sync_invoices($order, array('allow_defer' => false));
    			
    			$cancellations         = $order->get_finalized_cancellations();
    			$latest_cancellation = end($cancellations);
    
    			if ($latest_cancellation->has_file()) {
    				$attachments[] = $latest_cancellation->get_path();
    			}
    		}
    	}
    }
    Plugin Author vendidero

    (@vendidero)

    Hi,

    glad to hear! The code looks good to me ??

    Best,
    Dennis

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Attach Invoice Cancellation to custom order status email’ is closed to new replies.