• Resolved jdaldana

    (@jdaldana)


    Hi,

    We are using your plugin but just the basic/free version.
    We just simply want to add the tax ID number entered by our customer to the invoice.
    Can we add it somewhere in the invoice?

    I saw a code snippet in your website and I tried to edit it but failed.

    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_due_date', 10, 2 );
    function wpo_wcpdf_due_date ($template_type, $order) {
        if ($template_type == 'invoice') { // put due date only on invoice
            $invoice = wcpdf_get_invoice( $order );
            if ( $invoice_date = $invoice->get_date() ) {
                $due_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date->date_i18n('Y-m-d H:i:s') . ' + 14 days') );
                ?>
                <tr class="due-date">
                    <th>Due Date:</th>
                    <td><?php echo $due_date; ?></td>
                </tr>
                <?php
            }
        }
    }

    Can you please help on how to change this to show the Tax ID instead?
    Below is the code which I think get the tax ID:

    add_action('woocommerce_after_order_notes', 'taxexempt_after_order_notes' );
    function taxexempt_after_order_notes( $checkout ) {
    
            echo '<div style="clear: both"></div>
    
            <h3>Have Tax Exempt/Resale ID?</h3>';
    
            woocommerce_form_field( 'tax_exempt_checkbox', array(
                'type'          => 'checkbox',
                'class'         => array('tax-exempt-checkbox'),
                'label'         => __('Yes (Click Here)'),
                ), $checkout->get_value( 'tax_exempt_checkbox' ));
    
            woocommerce_form_field( 'tax_exempt_id', array(
                'type'          => 'text',
                'class'         => array('tax-exempt-id', 'update_totals_on_change'),
                'label'         => __('Please enter a valid Tax Exempt/Resale ID'),
                ), $checkout->get_value( 'tax_exempt_id' ));
    }

    Thanks,
    -JD

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor kluver

    (@kluver)

    Hi JD,

    I’m not quite sure where the tax_expempt_id is being stored but this filter should be a step in the right direction:

    add_filter( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_add_tax_id', 10, 2 );
    function wpo_wcpdf_add_tax_id( $template_type, $order ) {
    	if ( $template_type == 'invoice' ) {
    		$custom_field = $order->get_tax_exempt_id();
    		echo "<tr><td>Tax ID:</td><td>" . $custom_field . "</td></tr></div>";
    	}
    }

    If you have never worked with code snippets or functions.php please read this: Using filters

    It could be that tax_expempt_id is not stored in the order. Then it will not show up on the invoice. You could then check if you can find it under a different name with this guide: Finding custom fields

    I hope this helps you in the right direction.

    With kind regards.

    Michael

    Thread Starter jdaldana

    (@jdaldana)

    Hi Michael,

    Thank you for your feedback.

    I used Code Snippets and tried using the code you have provided but it didn’t work.
    The tax exempt ID is not saved as tax_exempt_id but rather Tax Exempt ID.
    I tried changing the tax_exempt_id to Tax Exempt ID but the snippets returned an error.

    Please view the link to see how it was saved (?) on the order.

    https://d.pr/ZplFqC

    Can you please advise on how to display the value on this situation?

    Thanks,
    -JD

    Plugin Contributor Ewout

    (@pomegranate)

    Hi JD,
    Thanks for sharing that screenshot, that certainly helps ??
    This should work:

    
    add_filter( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_add_tax_id', 10, 2 );
    function wpo_wcpdf_add_tax_id( $template_type, $order ) {
    	if ( $template_type == 'invoice' ) {
    		$tax_exempt_id= $order->get_meta('Tax Exempt ID');
    		echo "<tr><td>Tax ID:</td><td>{$tax_exempt_id}</td></tr>";
    	}
    }
    

    Let us know if you still have any questions!
    Ewout

    Thread Starter jdaldana

    (@jdaldana)

    Hi Ewout,

    Thank you for the code.
    They work indeed!
    I appreciate your (and Michael’s) time for this!

    Plugin Contributor Ewout

    (@pomegranate)

    Awesome, very glad to hear that!

    Ewout

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding Custom Field to Invoice’ is closed to new replies.