Support » Plugin: WooCommerce » Shows items in excluding tax cart – with price including tax

  • Resolved magicsun

    (@magicsun)


    Hi All,

    I have a cart setting to display prices excluding tax. But i need the items within the cart to be displayed including tax. (Only the items!)

    in cart.php I found this for item price:

    <td class="product-price" data-title="<?php _e( 'Price', 'woocommerce' ); ?>">
    						<?php
    							echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
    						?>
    					</td>

    And this for cart item subtotal:

    <td class="product-subtotal" data-title="<?php _e( 'Total', 'woocommerce' ); ?>">
    						<?php
    							echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key );
    						?>
    					</td>

    How can I edit these in a way, that they display the price including tax?

    I also found this snippet, but i’m not able to overwrite it with a child theme, as it’s in the includes folder of Woocommerce:

    public function get_product_price( $_product ) {
    if ( $this->tax_display_cart == 'excl' ) {
    $product_price = $_product->get_price_excluding_tax();
    } else {
    $product_price = $_product->get_price_including_tax();
    }
    return apply_filters( 'woocommerce_cart_product_price', wc_price(     $product_price ), $_product );
    }

    If I could set swap the “get_price_excluding_tax” and “get_price_including_tax” or maybe use these tags in a add filter hook for the above, that would be awesome.

    Anyone with PHP knowledge can help me out?

    Thanks!

    https://wordpress.org/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Hey magicsun,

    I’m not sure I understand why you want this (seems a bit inconsistent), but here ya go 🙂

    add_filter( 'woocommerce_cart_product_price', 'wc_ninja_cart_product_price', 15, 2 );
    function wc_ninja_cart_product_price( $product_price, $_product ) {
    	$incl_tax = $_product->get_price_including_tax();
    	return wc_price( $incl_tax );
    }
    
    add_filter( 'woocommerce_cart_product_subtotal', 'wc_ninja_cart_product_subtotal', 15, 4 );
    function wc_ninja_cart_product_subtotal( $product_subtotal, $_product, $quantity, $object ) {
    	$row_price  = $_product->get_price_including_tax( $quantity );
    	$incl_tax = wc_price( $row_price );
    
    	if ( ! $object->prices_include_tax && $object->tax_total > 0 ) {
    		$incl_tax .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
    	}
    
    	return $incl_tax;
    }

    May I thank you forever and ever? You made my easter-day! So far, it works, will have to test it with a test-order though. Whoohoo! Happy Easter!

    Let me explain why I wanted this ..

    I know, it sounds inconsistent, but unfortunately the tax-situation here in Holland doesn’t work with the regular settings of Woocommerce.

    Shipping prices in Holland that are known to the regular customer, are without tax. When you use the shipping service within Holland as a customer (directly at the post office, not buying at a business), you don’t pay tax. But as a business I need to add tax to my total amount, so that includes shipping as well.

    Therefor a package which normally costs 6,95 at the post office, now costs 8,40. I don’t want customers to see that it pays extra for shipping, because none of the webshops in Holland do that. Instead they calculate tax separately, or add extra to their products to get the costs even.

    Unfortunately in Woocommerce, you cannot choose to split shipping and tax, when using an including tax cart/checkout page. The customer does have to pay 8,40, but I don’t want that extra costs added to the shipping costs, I want it to only show in the “taxes” line. Customers know they have to pay tax, they just find it odd when the shipping costs are higher, or a different amount then they are used to at the post office.

    I’ve posted this on allot of dutch website’s, and allot of them tell me to enter shipping as 5,74. Because when you add 21% tax to 5,74, you get 6,95. But 6,95 is already a price without tax, so if I remove taxes on a already excluding tax price, that’s just wrong (and i’m pretty sure illegal as well). In the cart it will show 6,95, but I will lose 1,40 on every order (1,40 is the tax I have to pay over the 6,95).

    In Woocommerce, when you set cart/checkout to “excluding” it does exactly what I want with the totals. It divides costs and taxes, displays them separately and adds them up. Therefor my package is displayed at 6,95, the costs the customer is used to pay for. But I still get my taxes paid by the customer, because they are all combined within the “taxes” line in the cart totals.

    And that’s why I want to show prices of the products including, because my whole shop, is displayed including taxes. I’ve altered the table headers so it states clearly “(incl. BTW)” (dutch for tax).

    Now the customer doesn’t notice that it pays 21% tax over shipping, but it is added in the proper order: subtotal (excl), shipping (excl), tax, total (incl.)

    Could the same trick be done for the prices on the Thank You page and the emails? They display excluding taxes right now.

    The change of your code is done perfectly on the cart and review order page.

    Thank you page:
    Not sure what displays the items table. Can’t find it within the thank you template.

    Emails:
    woocommerce_email_order_items_table
    is used to display the table within the email, but in the email template I can’t find anything about price.

    Many thanks!

    Fixed the item subtotal within emails.
    In Child theme > woocommerce > templates > email > email_order_items.php

    Find this:
    <?php echo $order->get_formatted_line_subtotal( $item ); ?>

    change it into:
    <?php echo $order->get_formatted_line_subtotal( $item, 'total', 'incl' ); ?><small>(incl. BTW)</small>

    That displays the order item total including taxes.

    If anyone has a solution for the Thank you page. For now I think i’ll remove the
    do_action( 'woocommerce_order_items_table', $order );
    from the thankyou.php file, so that it won’t display all the info again. They get it emailed anyway.

    Great Caleb Burks!
    I ask to woocommerce support and after a few posts they said they can not give this support!!!
    You are fantastic!
    Thanks

    Hi!

    I am very glad this solution, thank you! Although it has only half a solution for me. I would also need add to a minicart may include tax as to subtotal. The inserted code just add to the items to the tax.
    Can you help, what would be the solution? I do not have too much PHP practice.

    Thanks in advance!

    Lui

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Shows items in excluding tax cart – with price including tax’ is closed to new replies.