• Resolved psodfj

    (@psodfj)


    Hi,
    We have a bunch of EU VAT-related custom fields that appear based on a “Issue invoice” checkbox in the checkout process. We have made a custom template to show them in the invoice but how could we force the plugin to generate (or email) an invoice whenever the checkbox is selected?

    The goal is to auto-generate the invoices only for the orders which explicitly require it (through the checkbox).

    Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    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;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Process PDF based on a custom field?’ is closed to new replies.