• Resolved bggg12

    (@bggg12)


    I have set the prices to be displayed incl. VAT during cart and checkout. By default, Woocommerce then adds a .tax_label after the subtotal, and a .includes_tax after the total. For customers from countries with 0% VAT, nothing is displayed, I need the tax_label and includes_tax to be displayed though as “excl. VAT”. How can I do this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello @bggg12 ,

    That’s an interesting approach.

    By default, WooCommerce keeps it blank for 0% taxed countries. Assing the tax label for these will require some customizations. Here is an example code that you can use under your current theme’s functions.php file or using a snippet plugin

    
    // Adds tax label for non-taxed countries
    
    add_filter( 'woocommerce_cart_product_subtotal', 'modify_cart_product_subtotal_label', 10, 4 );
    
    function modify_cart_product_subtotal_label( $product_subtotal, $product, $quantity, $cart ) {
        // Add your logic here.
        // You can use the $cart instead of using the global $woocommerce variable.
    
    	if ($cart->get_subtotal_tax() == 0) {
    		$product_subtotal .= ' <small class="tax_label">excl. VAT</small>';
    	}
    
        return $product_subtotal;
    }
    
    add_filter( 'woocommerce_cart_subtotal', 'modify_cart_subtotal_label', 10, 3 );
    
    function modify_cart_subtotal_label( $cart_subtotal, $compound, $cart ) {
        // Add your logic here.
        // You can use the $cart instead of using the global $woocommerce variable.
    
    	if ($cart->get_subtotal_tax() == 0) {
    		$cart_subtotal .= ' <small class="tax_label">excl. VAT</small>';
    	}
    
        return $cart_subtotal;
    }

    If you need more customization consider taking help from professional developers. You can find our recommended developers here.

    Thank you ??

    Thread Starter bggg12

    (@bggg12)

    @rur165 Thank you very much! This works very well. The only thing missing is that “excl. VAT” in the order-totals. Do you maybe know how to apply it there as well?

    • This reply was modified 3 years, 10 months ago by bggg12.

    Hello @bggg12 ,

    I am glad that this was helpful.

    We do have a filter for cart total as well. You can use a similar format of solution for it as well –

    add_filter( 'woocommerce_cart_totals_order_total_html', function($value) {
    
    		if (WC()->cart->get_subtotal_tax() == 0) {
    			$value .= ' <small class="tax_label">excl. VAT</small>';
    		}
    
    	    return $value;
    } );

    Thank you ??

    Thread Starter bggg12

    (@bggg12)

    Thank you very much!!

    Thread Starter bggg12

    (@bggg12)

    @rur165 Sorry for opening this again: How can I also display it in the order emails? Unfortunately it is not displayed there.

    Thanks!

    Hello @bggg12 ,

    WooCommerce only shows the tax information in the total amount field in order confirmation emails. So, you can use this format to include your information –

    // define the woocommerce_get_formatted_order_total callback 
    function filter_woocommerce_get_formatted_order_total( $formatted_total ) { 
    
    	if (WC()->cart->get_subtotal_tax() == 0) {
    			$tax_string = '  <small class="tax_label">excl. VAT</small>';
    			$formatted_total .= $tax_string;
    		}
        
    
        return $formatted_total; 
    }; 
             
    // add the filter 
    add_filter( 'woocommerce_get_formatted_order_total', 'filter_woocommerce_get_formatted_order_total', 10, 2 );

    Thank you ??

    I hope the above helped. We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread. Cheers!

    Hello,
    Thanks a lot for the above codes ! <3
    I had the exact same need…

    Question :
    How could I display the “excl. tax” on the single-product pages ?

    As we may add taxes to only specific countries (European Union for me), it would be great if the “Price display suffix” option (in WooCommerce > Settings > Tax) would be split between : including tax suffix & excluding tax suffix…

    Thank you in advance ! (:

    Hello again,

    However, the last function :

    // define the woocommerce_get_formatted_order_total callback 
    function filter_woocommerce_get_formatted_order_total( $formatted_total ) { 
    
    	if (WC()->cart->get_subtotal_tax() == 0) {
    			$tax_string = '  <small class="tax_label">excl. VAT</small>';
    			$formatted_total .= $tax_string;
    		}
        
        return $formatted_total; 
    };         
    // add the filter 
    add_filter( 'woocommerce_get_formatted_order_total', 'filter_woocommerce_get_formatted_order_total', 10, 2 );

    creates an ‘Error 503 Backend fetch failed’ in my woocommerce > orders page …

    Thank you ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Display tax label’ is closed to new replies.