Add a Column to Show Order Item Price Excl. Tax in Woocommerce Email Notifications
Image by Manon - hkhazo.biz.id

Add a Column to Show Order Item Price Excl. Tax in Woocommerce Email Notifications

Posted on

Are you tired of receiving Woocommerce email notifications that don’t provide the detailed information you need? Specifically, are you looking for a way to add a column that shows the order item price excluding tax in these email notifications? You’re in the right place! In this article, we’ll guide you through the process of adding this essential column to your Woocommerce email notifications, giving you a clearer picture of your order details.

Why Add a Column for Order Item Price Excl. Tax?

Before we dive into the tutorial, let’s quickly discuss why adding a column for order item price excluding tax is so important.

  • Accuracy and Transparency**: Providing this information ensures accuracy and transparency in your order notifications. It gives you and your customers a clear understanding of the order item prices, making it easier to identify any discrepancies.
  • Better Decision Making**: With this information, you can make more informed decisions about your business, such as identifying trends, optimizing pricing strategies, and improving customer satisfaction.
  • Enhanced Customer Experience**: By providing detailed information, you can enhance the customer experience, reduce confusion, and build trust with your customers.

Step 1: Create a Custom Function to Add the Column

To add the column, we’ll create a custom function using PHP. Don’t worry if you’re not familiar with coding; we’ll walk you through it step-by-step.


// Add a new column to the order items table
function add_order_item_price_excl_tax_column($columns) {
    $columns['price_excl_tax'] = __('Price excl. Tax', 'woocommerce');
    return $columns;
}
add_filter('woocommerce_email_order_items_table_columns', 'add_order_item_price_excl_tax_column');

// Add the data for the new column
function add_order_item_price_excl_tax_data($item, $order) {
    $price_excl_tax = wc_get_order_item_meta($item['item_id'], '_line_subtotal', true);
    $tax_amount = wc_get_order_item_meta($item['item_id'], '_line_tax', true);
    $price_excl_tax = $price_excl_tax - $tax_amount;
    echo '' . wc_price($price_excl_tax) . '';
}
add_action('woocommerce_email_order_items_table_item_meta', 'add_order_item_price_excl_tax_data', 10, 2);

Copy and paste the above code into your theme’s functions.php file. This code creates a new column called “Price excl. Tax” and adds the data for each order item.

Step 2: Modify the Email Template

Now that we’ve created the custom function, we need to modify the email template to display the new column.

Locate the email-order-items.php file in your theme’s woocommerce directory. If the file doesn’t exist, you can create a new one or copy it from the Woocommerce plugin directory.


<table>
    <thead>
        <tr>
            <th><?php _e('Product', 'woocommerce'); ?>></th>
            <th><?php _e('Quantity', 'woocommerce'); ?>></th>
            <th><?php _e('Price', 'woocommerce'); ?>></th>
            <th><?php _e('Price excl. Tax', 'woocommerce'); ?>></th> 
            <th><?php _e('Subtotal', 'woocommerce'); ?>></th>
        </tr>
    </thead>
    <tbody>
        <?php
        foreach ($order_items as $item) :
            &$lt;tr>
                <td><?php echo $item['name']; ?>></td>
                <td><?php echo $item['qty']; ?>></td>
                <td><?php echo $order->format_line_subtotal($item); ?>></td>
                <td><?php add_order_item_price_excl_tax_data($item, $order); ?>></td> 
                <td><?php echo $order->format_line_subtotal($item); ?>></td>
            </tr>
        endforeach;
        ?>
    </tbody>
</table>

Update the email-order-items.php file with the above code. This will add the new column to the email template.

Step 3: Style the New Column

Let’s add some basic styling to our new column.


<style>
    .price-excl-tax {
        text-align: right;
        width: 15%;
    }
</style>

Add the above CSS code to your theme’s stylesheet (style.css) or use a CSS plugin to add custom styles.

Final Result

After adding the custom function, modifying the email template, and styling the new column, your Woocommerce email notifications should now display the order item price excluding tax.

Product Quantity Price Price excl. Tax Subtotal
Product 1 2 $20.00 $18.00 $36.00
Product 2 3 $30.00 $27.00 $81.00

Now you and your customers can easily view the order item price excluding tax in the email notifications.

Tips and Variations

If you want to take it a step further, here are some tips and variations to consider:

  • Display the tax rate**: You can modify the code to display the tax rate alongside the price excluding tax.
  • Format the prices**: Use Woocommerce’s built-in price formatting functions to display the prices in your preferred format.
  • Conditional logic**: Add conditional logic to hide or display the new column based on specific conditions, such as order type or customer group.

With these instructions, you should now be able to add a column to show order item price excluding tax in your Woocommerce email notifications. Remember to test your code and email templates to ensure everything is working as expected.

Happy coding, and don’t hesitate to ask if you have any questions or need further assistance!

Here are 5 questions and answers about “Add a column to show order item price excl. tax in Woocommerce email notifications” :

Frequently Asked Question

Get the answers to your most pressing questions about adding a column to show order item price excl. tax in Woocommerce email notifications!

Why do I need to add a column to show order item price excl. tax in Woocommerce email notifications?

Adding a column to show order item price excl. tax in Woocommerce email notifications provides transparency and clarity to customers about the prices they are paying. It helps to build trust and ensures that customers are aware of the taxes applied to their orders.

How do I add a column to show order item price excl. tax in Woocommerce email notifications?

You can add a column to show order item price excl. tax in Woocommerce email notifications by using a custom function in your theme’s functions.php file or by using a plugin like Woocommerce Email Customizer. You can also use a shortcode to display the price excl. tax in the email notification template.

Will adding a column to show order item price excl. tax affect the performance of my Woocommerce store?

No, adding a column to show order item price excl. tax in Woocommerce email notifications will not significantly affect the performance of your store. The function only modifies the email notification template and does not impact the core functionality of your store.

Can I customize the appearance of the column to show order item price excl. tax in Woocommerce email notifications?

Yes, you can customize the appearance of the column to show order item price excl. tax in Woocommerce email notifications by using CSS styles or by modifying the email notification template. You can also use plugins like Woocommerce Email Customizer to customize the email template.

Is it possible to add multiple columns to show different prices in Woocommerce email notifications?

Yes, it is possible to add multiple columns to show different prices in Woocommerce email notifications. You can use a combination of custom functions and shortcodes to display different prices, such as prices incl. tax, prices excl. VAT, or prices with discounts applied.

Leave a Reply

Your email address will not be published. Required fields are marked *