1 min read

WooCommerce Shipping Calculated after Coupon

WooCommerce Shipping Calculated after Coupon

The WooThemes team have to consider many edge cases when they develop WooCommerce. Occasionally we have to add bespoke functionality when the out of the box solution does not work as we require.

One of our clients is running a campaign which discounts £40 off the order value. They also use the Table Rate Shipping extension to charge a £10 shipping cost for orders under £100.

However WooCommerce calculates the shipping cost before the coupon is added and therefore if an order is more than £100 before the coupon and under £100 after a coupon then the customer receives free shipping when they shouldn’t.

Example

Order Total = £130 | Free Shipping

If I have an coupon which takes £40 off then

Order Total = £130 – £40 = £90

For this order we should be charging the £10 shipping as the total order is under £100. Currently WooCommerce does not do this. In this situation we need to calculate the shipping rules based on the total after the discount is calculated.

If you have this issue then the modification below will calculate shipping based on the discounted total. Hopefully this modification becomes redundant one day as we think this is a better way to manage shipping rules.

If there is a reason that this is not default then please let us know in the comments.

The Code

https://gist.github.com/d7b0275018d8b78a5492

To use please add this to your theme’s function.php file.