WooCommerce Colorado Retail Delivery Fee

WooCommerce checkout showing Colorado Retail Delivery Fee


There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

As of July 1st 2022, The Department of Revenue in Colorado, United States, is implementing a new “Retail Delivery Fee” as detailed here. This statute effectively says a flat $0.27 fee per order must be added for any orders which are delivered by motor vehicle to an address in Colorado and it must show on the receipt or invoice as one item called “Retail Delivery Fee”.

This snippet adds ‘CO’ (the select option value for Colorado) to an array we’ve called ‘state’. We have made this variable an array should any other states implement this Retail Delivery Fee in the future.

This snippet then grabs the user’s chosen shipping method from the checkout session (the state drop-down list).

Then, this is where the magic happens. The snippet uses an if statement to check whether both the chosen shipping state is in the array we declared earlier (is CO the chosen shipping state) AND if the chosen shipping method is the flat rate method. Keep in mind, you are going to have to change the shipping method option value ‘flat_rate:10’ to whatever yours is set to. You can find the shipping method option value info using this guide.

If both conditions are met, a $0.27 surcharge is added to the order and displayed as part of the order summary. This surcharge is added as a fee and labelled “Retail Delivery Fee” as requested by Colorado’s Department of Revenue.

By default, WooCommerce does not refresh the order summary to show this fee should it apply. This is where some JavaScript comes in. This JavaScript section of the code snippet will update the order summary to reflect the fee when the State has been selected, meaning your customers are not hit with any surprise fees post purchase.

You’ll notice the Retail Delivery Fee will be shown on the Checkout, Thank You Page, My Account Order View, Admin Dashboard Order View, and all emails.

 * Snippet Name:	WooCommerce Colorado Retail Delivery Fee
 * Snippet Author:

// Add the $0.27 fee
add_action( 'woocommerce_cart_calculate_fees','ecommercehints_colorado_retail_delivery_fee' );
function ecommercehints_colorado_retail_delivery_fee() {
	global $woocommerce;
	if (is_admin() && !defined('DOING_AJAX'))
 	$state = array('CO'); // CO is the select option value for Colorado
	$chosen_shipping_method = WC()->session->get('chosen_shipping_methods')[0]; // Get the shipping method

	 * If shipping state equals Colorado AND shipping method is your flat rate options, add the fee
	 * You will need to change 'flat_rate:10' to your flat rate shipping method radio button value
	if ( in_array( $woocommerce->customer->get_shipping_state(), $state ) && 'flat_rate:10' === $chosen_shipping_method):
		$woocommerce->cart->add_fee( 'Retail Delivery Fee', 0.27, false, '' ); // False means tax will not be applied on top

// JavaScript to update the totals on state selection
add_action( 'wp_footer', 'ecommercehints_update_checkout_totals' );
function ecommercehints_update_checkout_totals() { ?>
	jQuery( function( $ ) {
	$( 'form.checkout' ).on( 'change', 'select[name^="billing_state"]', function() {
		$( 'body' ).trigger( 'update_checkout' );
<?php }

Snippet Benefits

  • Comply with local state laws.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.