How to get woocommerce orders total sales without taxes?

Member

by deron , in category: PHP CMS , a year ago

How to get woocommerce orders total sales without taxes?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by muriel.schmidt , a year ago

@deron 

To get WooCommerce orders total sales without taxes, you can use the following code in your functions.php file or in a custom plugin:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function get_total_sales_without_tax() {
    $args = array(
        'post_type'      => 'shop_order',
        'post_status'    => array_keys(wc_get_order_statuses()),
        'posts_per_page' => -1,
        'fields'         => 'ids',
    );
    
    $orders_ids = get_posts( $args );

    $total_sales = 0;
    
    foreach ( $orders_ids as $order_id ) {
        $order = wc_get_order( $order_id );
        
        $total_sales += $order->get_total() - $order->get_total_tax();
    }
    
    return $total_sales;
}

$woocommerce_sales_without_tax = get_total_sales_without_tax();

echo 'Total sales without tax: ' . wc_price( $woocommerce_sales_without_tax );


This function will query all orders in WooCommerce, loop through each order, subtract the total tax amount from the order total, and then calculate the total sales amount without taxes. Finally, it will display the total sales without tax using the wc_price() function.


You can call this function wherever you want in your theme or template files to display the total sales without taxes.

Related Threads:

How to get total sum of orders by a user in woocommerce?
How to get orders by user meta data in woocommerce?
How to get custom fields values from woocommerce orders?
How to get the total bundle size when building with vite?
Where does woocommerce store orders?
How to limit the frequency of woocommerce orders?