Generate PDF Only for “con_fattura” Payment Method
-
Hi everyone,
I need help configuring the automatic generation of PDF invoices only when a specific payment method is selected. My payment option is “con_fattura”.
I found and used this code in an old thread to exclude certain payment methods from automatic PDF generation:
add_filter('wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_exclude_payment_method', 100, 4);
function wpo_wcpdf_exclude_payment_method($condition, $order, $status, $document) {
$excluded_methods = array('stripe', 'bacs');
$payment_method = get_post_meta($order->id, '_payment_method', true);
if ($document == 'invoice' && in_array($payment_method, $excluded_methods)) {
return false;
} else {
return $condition;
}
}
Unfortunately, this code didn’t work as I wanted. So I developed this code to include the PDF only for the “con_fattura” payment method:add_filter('wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_include_specific_payment_method', 10, 4);
function wpo_wcpdf_include_specific_payment_method($condition, $order, $status, $document) {
$included_methods = array('con_fattura');
$payment_method = get_post_meta($order->get_id(), '_payment_method', true);
if ($document == 'invoice' && in_array($payment_method, $included_methods)) {
return true;
} elseif ($document == 'invoice') {
return false;
} else {
return $condition;
}
}However, this code also doesn’t work correctly. Has anyone faced and resolved a similar situation? How can I configure the PDF generation only when the selected payment method is “con_fattura”?
Thanks in advance for your help!
- You must be logged in to reply to this topic.