Show Woocommerce Total Sales anywhere in page using shortcode

// Add this code to your theme's functions.php file or a custom plugin

function net_sales_shortcode() {
    // Make sure WooCommerce is active
    if (class_exists('WooCommerce')) {
        // Get completed and processing orders
        $order_statuses = array('completed', 'processing');
        $completed_orders = wc_get_orders(array(
            'status' => $order_statuses,
            'limit'  => -1, // Get all orders
        ));

        // Initialize net sales amount
        $net_sales = 0;

        // Loop through completed and processing orders
        foreach ($completed_orders as $order) {
            // Get order total (excluding taxes and shipping)
            $order_net_total = $order->get_total() - $order->get_total_tax() - $order->get_shipping_total();
            
            // Add order net total to the net sales amount
            $net_sales += $order_net_total;
        }

        // Return the net sales amount
        return wc_price($net_sales);
    } else {
        // WooCommerce is not active
        return 'WooCommerce is not installed or activated.';
    }
}

// Register the shortcode
add_shortcode('total_purchase', 'net_sales_shortcode');