PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 3, 2022

[FIXED] Get total tax amount in the checkout - woocommerce

 March 03, 2022     php, woocommerce, wordpress     No comments   

Issue

I changed checkout price to 600€ with code below:

add_filter( 'woocommerce_order_amount_total', 'custom_cart_total' );
function custom_cart_total($order_total) {
  return $order_total = 600;
}

add_action( 'woocommerce_review_order_before_order_total', 'mod_cart_total' );
function mod_cart_total() {

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;

    WC()->cart->total = 600;
}

Now, I need to exclude tax from this price. My idea was deduct variable in which the tax value is stored from total price , but I cannot find how to get total tax amount.


Solution

You can use either:

WC()->cart->get_tax_totals( ); //gives total taxes

WC()->cart->get_taxes( ); //gives an array of all taxes

As described here: https://woocommerce.github.io/code-reference/classes/WC-Abstract-Order.html#method_get_taxes and here: https://woocommerce.github.io/code-reference/classes/WC-Cart.html#method_get_taxes_total



Answered By - Growdzen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing