I think I may have figured out how to do this for my purposes. Is there any problem with the following snippet?
add_filter('wpo_wcpdf_custom_attachment_condition', 'ms_no_invoice_failed_orders', 10, 4);
function ms_no_invoice_failed_orders ($attach, $order, $email_id, $document_type){
if ($order->get_status() == 'failed') {
return false;
}
return $attach;
}
Plugin Contributor
Ewout
(@pomegranate)
Looks good to me! Are you getting errors with this snippet?
No errors – it’s working well as far as I can tell.
I mainly wasn’t sure if it would be more comprehensive to do something with the $document_type argument. My client’s use-case only includes invoices at the present time, so since that’s the only document they are generating, I ignored it.
Is there any documentation for the wpo_wcpdf_custom_attachment_condition filter anywhere? I only found it by digging through the plugin code.
It’s a very nice plugin.
Plugin Contributor
Ewout
(@pomegranate)
There’s no specific documentation, it receives 4 arguments: $attach, $order, $email_id, $document_type. Return false to disable attachment, true to enable.
Indeed you could use the $document_type variable to limit the condition to a specific document (although the free version only attaches the invoice anyway). In your case:
add_filter('wpo_wcpdf_custom_attachment_condition', 'ms_no_invoice_failed_orders', 10, 4);
function ms_no_invoice_failed_orders ($attach, $order, $email_id, $document_type){
if ($document_type == 'invoice' && $order->get_status() == 'failed') {
return false;
}
return $attach;
}