Support » Plugin: WooCommerce PDF Invoices & Packing Slips » tax displayed is incorrect

  • Resolved JeanPaul1

    (@jeanpaul1)


    On the invoice it show the price details, like subtotal, discount shipping and so on.
    It also show the tax line. Problem is, it shows the wrong label. It show VAT but it should show Tax Exempt. In all other files it shows correctly, email, order-review, orders except in the invoice. How can I change this?
    Is there a hook?
    Can I change it so it will use the correct tax label?
    Thank you

    • This topic was modified 3 years ago by JeanPaul1.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hello Jean Paul,
    That is quite strange, the free version of this plugin normally shows the exact same output for the taxes as the email, like so in the email:

    and the same in the PDF:

    That is to say, unless you have made changes to the template.

    Could you post three screenshots from 1 and the same order with this issue showing:

    1. The PDF totals
    2. The totals in the backend
    3. The totals in the email

    Can you also double check that you are using the default “Simple” template in the PDF Invoice settings?

    Thread Starter JeanPaul1

    (@jeanpaul1)

    Hello Ewout

    Here are the screenshots

    I am using simple but copied it to my theme folder.
    I switched the invoice number with order number and added some characters to it.
    Everything else is the same.

    • This reply was modified 3 years ago by JeanPaul1.
    Plugin Contributor Ewout

    (@pomegranate)

    Hello Jean Paul,
    The separate tax row is not a default output from WooCommerce, that would be as in my previous screenshots (which in your example would then show “Totaal €103.50 includes €0.00 vrijgesteld van BTW” instead of btw: €0.00, €totaal: €103.50). This probably means that either more elements have been changed in the template than you mentioned (I also see a column “Image” that isn’t in the Simple template), or that the order item totals have been filtered elsewhere in WooCommerce. Your screenshots did not include number 2 “The totals in the backend”. Could you also post that? Make sure that not only the totals but also the products and the column headers are visible.

    For testing purposes I would recommend to temporarily switch to the Simple template to see if that gives a different output.

    Thread Starter JeanPaul1

    (@jeanpaul1)

    Hello Ewout

    I have in the backend woocommerce set the option ‘Display tax totals’ As a Single total.
    So I believe this is standard btw: €0.00, €totaal: €103.50) behaviour when this option is selected.
    see official ducumentation of woocommerce
    Setting up Taxes in WooCommerce
    But maybe I’m wrong

    Here are the screenshots, hope I have the correct one’s now.
    All is standard, removed everything from my theme folder so it uses directly the files from the plugin without any alteration. Except that I enabled images in the emails but this is a oneliner code.
    On checkout and order-review and thankyou page and in acccount page it all shows the same BTW-vrijgesteld.



    I think the problem is that the &tax_label is not taken from woocommerce directly but that this is done inside pdf invoices and packing slips
    I saw in your code function get_order_taxes(), get_order_grand_total( $tax = ‘incl’ ), get_formatted_item_price ( $item, $type, $tax_display = ” ) and they all add there own labels. Is there no hook like ‘woocommerce_get_order_item_totals’ so I can change the label accordingly?

    • This reply was modified 3 years ago by JeanPaul1.
    • This reply was modified 3 years ago by JeanPaul1.
    Thread Starter JeanPaul1

    (@jeanpaul1)

    Image form the invoice.
    Image invoice

    • This reply was modified 3 years ago by JeanPaul1.
    • This reply was modified 3 years ago by JeanPaul1.
    Thread Starter JeanPaul1

    (@jeanpaul1)

    One more thing, since the last update of Woocommerce this code snippet is not working anymore.

    add_action( 'wpo_wcpdf_after_order_details', 'wpo_wcpdf_custom_text', 15, 5 );
    function wpo_wcpdf_custom_text ($template_type, $order) {
        
        if ($template_type == 'invoice') {
            ?>
            <div class="custom-text">
    		<?php _e(sprintf('Bedankt voor je bestelling %s, we gaan snel aan de slag om deze bij je thuis te leveren.',$order->get_billing_first_name()));?>
            </div>
            <?php
        }
    }

    Is this function not valid anymore with the new update?

    Plugin Contributor Ewout

    (@pomegranate)

    Hello Jean Paul,
    I don’t see any taxes at all in the order screenshots, so there is no tax label to be taken either. These functions you mention from the free version (get_order_taxes and get_order_grand_total) are not used in the Simple template and the totals from woocommerce (get_woocommerce_totalsuse the tax labels as recorded in the order, for that matter, none of this is overriden).
    If there would be taxes in the order, it should show a column besides the product price and a row in the totals. But yours is tax exempt so under normal circumstances (even with the option to display as a single total enabled, tested to confirm), it wouldn’t show any tax. As a single total it would still show the taxes as “Total: #.## including #.## tax”. This “tax” label comes directly from WooCommerce by calling the function WC()->countries->tax_or_vat(): https://github.com/woocommerce/woocommerce/blob/3.6.4/includes/class-wc-order.php#L166-L174

    That ‘btw’ row is added somewhere else, because by default WooCommerce wouldn’t show 0.00 taxes. Are you using a plugin for this tax exemption?

    Thread Starter JeanPaul1

    (@jeanpaul1)

    I have this filter
    add_filter( ‘woocommerce_cart_hide_zero_taxes’, ‘__return_false’, 100 );
    So I think this will make sure that zero tax is displayed.

    I’m not using a plugin for tax exempt.
    I wrote my own code.
    To set customer tax-exempt I use this

    /* 
    *  Update cart with VAT_EXEMPT
    */
    add_action( 'woocommerce_checkout_update_order_review', 'taxexempt_checkout_based_on_checkbox');
    function taxexempt_checkout_based_on_checkbox( $post_data) {
    	global $woocommerce;	
        $woocommerce->customer->set_is_vat_exempt( false );
        parse_str($post_data);
    
        if ( $billing_taxexempt === '1' && $billing_confirmed === '1' && !empty($billing_signature) && ! empty($billing_declaration)){
    		$woocommerce->customer->set_is_vat_exempt( true );	
    		add_filter( 'woocommerce_countries_tax_or_vat', function () { return __( 'Tax Exempt', 'woocommerce' ); }); 
    		
    	} 
    }
    

    This will display the tax total line. I added a filter to change the ‘VAT’ to ‘Tax Exempt’

    Then I added this code

    add_filter( 'woocommerce_get_order_item_totals', 'wc_get_order_item_totals', 10, 5); 
    function wc_get_order_item_totals( $total_rows, $order_id, $tax_display ) { 
    	
    	$order = wc_get_order( $order_id ); 
    
    	$taxexempt = get_post_meta( $order->get_id(),'_billing_taxexempt', true );
    	if($taxexempt == 1){	
               $total_rows['tax'] = array( 
    		'label' => __( 'Tax Exempt', 'woocommerce' ), 
    		'value' =>  wc_price( $order->get_total_tax() ), 
    		); 
    	} else{
    		 $total_rows['tax'] = array( 
    		'label' => __( 'VAT', 'woocommerce' ), 
    		'value' =>  wc_price( $order->get_total_tax() ), 
    		);
    	}
    	return $total_rows; 
    
    }

    To make it change everywhere else.
    As you wrote “This “tax” label comes directly from WooCommerce by calling the function WC()->countries->tax_or_vat(): ”
    There is a filter available to change the label, which I used in the code.
    When you follow your link you will see it at the bottom.

    /**
    * Filter WooCommerce formatted order total.
    *
    * @param string $formatted_total Total to display.
    * @param WC_Order $order Order data.
    * @param string $tax_display Type of tax display.
    * @param bool $display_refunded If should include refunded value.
    */
    return apply_filters( ‘woocommerce_get_formatted_order_total’, $formatted_total, $this, $tax_display, $display_refunded );

    So what am I doing wrong?
    Should this not be visible everywhere, including invoices?
    Or am I using the wrong hook?
    Will try an other one and let you know.

    • This reply was modified 3 years ago by JeanPaul1.
    Thread Starter JeanPaul1

    (@jeanpaul1)

    Okay I found a solution that seems to be working now.
    Order 576 without tax exempt applied

    Order 575 with tax exempt applied

    I used this code snippet By LoicTheAztec
    I changed it a little bit to show ‘label’ => __( ‘Tax Exempt’, ‘woocommerce’ ),
    Removed the default tax line and added the new one with the code.

    and I found this code online EXAMPLE #13

    I just copy and paste it to do a trial run with it and it just worked.
    Nice bonus, the code for adding text to the invoice did not work before but now it does.
    You can see the text in the images, before this never showed up.

    Plugin Contributor Ewout

    (@pomegranate)

    Fantastic, glad to hear you found the culprit 🙂
    Happy selling!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘tax displayed is incorrect’ is closed to new replies.