Hi @stijndemulder,
This is certainly possible using a checkout custom field. You could use a plugin like Checkout Field Editor, for instance, to add your checkbox/radio custom field to the billing fields. Let’s say that you named your field billing_want_invoice
and the value when checked is yes
, then you could add a code snippet like this to enable the invoice only if the customer checked the field:
/**
* Enable invoice if customer wants it
*/
add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_allow_invoice_or_proforma_based_on_customer_selection', 10, 2 );
function wpo_wcpdf_allow_invoice_or_proforma_based_on_customer_selection( $allowed, $document ) {
if ( $order = $document->order ) {
if ( $want_invoice = $order->get_meta( 'billing_want_invoice' ) ) {
if( $document->type == 'invoice') {
$allowed = ($want_invoice == 'yes') ? true : false;
}
}
}
return $allowed;
}
Let me know if you manage to make it work ??