How to Add Extra Charges to WooCommerce Checkout

WooCommerce Extra Charges To WooCommerce Checkout

Are you searching for an easy way to add extra fees to the checkout in your WooCommerce store?

In today’s tutorial, we will show you how to add fees to the WooCommerce checkout programmatically to help you maximize your revenue.

There are times when you may need customers to pay an additional charge during the checkout.

The good news is that WooCommerce provides you with a lot of flexibility to customize and add the charges to the order cycle.

When to Add Fees to the WooCommerce Checkout?

Here are some of the common situations where you need to add fees during checkout:

  • Handling Fees – This is an additional charge you include when you have to deliver products that are considered fragile. These are products that can be easily damaged and need to be transported with extra care and special packaging.
  • Payment Gateways – You might want to transfer transactional charges to your customers depending on the payment methods you accept in your store.
  • Taxable Amount – If you do not want to include the tax in the product price, you can add it as an additional charge on the checkout.

It is worth mentioning that using code snippets to customize your store is not always easy.

However, it gives you much control over the customization you make compared to plugins.

This means that this solution is reserved for those who have coding skills. But we will try to explain each step in detail.

To achieve this, we need to modify WooCommerce’s core files.

Editing these files is a delicate process. If you make any mistake, an error will be displayed on your site. Therefore, we recommend using a child theme.

Let us get right into it.

Steps to Add Fees to the WooCommerce Checkout

Here are the steps you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to add an extra charge on the WooCommerce checkout page.
  3. Add the following code to the PHP file:
add_action('woocommerce_cart_calculate_fees', function() {
if (is_admin() && !defined('DOING_AJAX')) {
return;
}
WC()->cart->add_fee(__('Additional Charge', 'txtdomain'), 10);
});

  1. The code snippet above adds a flat fee of $10 called an Additional Charge.
  2. It will be added to the total of the customers’ checkout page automatically. This is the outcome:additional charge
  3. Alternatively, you can add a percentage fee. If you want to ass this functionality, add the following code:
add_action('woocommerce_cart_calculate_fees', function() {
if (is_admin() && !defined('DOING_AJAX')) {
return;
}
$percentage = 0.04;
$percentage_fee = (WC()->cart->get_cart_contents_total() + WC()->cart->get_shipping_total()) * $percentage;
WC()->cart->add_fee(__('Tax', 'txtdomain'), $percentage_fee);

  1. This is the outcome:tax

Conclusion

In today’s post, we have shared two code snippets to add an additional charge on the checkout page. In addition, we have also highlighted some of the reasons for adding extra fees to the checkout.

It is important to label the extra fee to avoid cart abandonment clearly. We recommend that you be transparent with your fees. Alternatively, you can use a plugin to customize the checkout page.

We hope that this post helped you learn more about how the checkout page works.

Similar Articles