Hello @psodfj
That checkbox is saved in which meta data? Order?
Thread Starter
psodfj
(@psodfj)
Hi @alexmigf
Thanks for the reply! I should’ve been clearer.
The checkbox and the VAT fields are custom fields added with a filter to woocommerce_checkout_fields
here is how they look:
$fields['billing']['billing_to_company'] = array(
'type' => 'checkbox',
'label' => __( 'Do you want a company invoice?', 'woo-bg' ),
'class' => array(
'form-row-wide',
),
'id' => 'woo-billing-to-company',
'priority' => 119,
);
$fields['billing']['billing_company_mol'] = array(
'label' => __( 'MOL', 'woo-bg' ),
'required' => true,
'class' => array(
'form-row-first',
'woo-bg-company-info',
),
'id' => 'woo-bg-billing-company-mol',
'priority' => 121,
);
I hope this answers your question.
Plugin Contributor
kluver
(@kluver)
Hi @psodfj,
The following filter will only allow invoice creation (automatic or manually) when the ‘Do you want a company invoice?’ option is checked:
add_filter( 'wpo_wcpdf_document_is_allowed', 'wpo_wcpdf_only_allow_invoice_when_explicitly_requested', 10, 2 );
function wpo_wcpdf_only_allow_invoice_when_explicitly_requested ( $condition, $document ) {
if ( $document->type == 'invoice' ) {
$condition = empty( $document->order->get_meta( '_billing_to_company' ) ) ? false : $condition;
}
return $condition;
}