skip to Main Content

Here in Colorado, our department of revenue is implementing a new "Retail Delivery Fee." It is a flat $0.27 per order on orders delivered by motor vehicle within Colorado. While most news reports focus on food delivery services like Grubhub, Doordash, etc., it also applies to anything shipped by FedEx, USPS, or UPS.

I can think of two ways to implement it in Woocommerce, but not sure how to actually do it:

  1. Add a new Flat Fee shipping charge to in-state deliveries.
  2. Add an additional Tax line.

Since it is actually a tax (though it’s called a "fee") I’m leaning toward 2), but I don’t know how to charge a tax only on orders that are shipped in-state.
If I opted for 1), I don’t know how to "stack" shipping fees on an order.

Some requirements:

  • charged on all orders that are shipped within Colorado (if a customer does a local pickup, I don’t need to charge this).
  • line item must be labeled as "Retail Delivery Fee" on invoices and sales orders.

Any suggestions?
Thanks!

2

Answers


  1. /**
     * Snippet Name:    WooCommerce Colorado Retail Delivery Fee
     * Snippet Author:  ecommercehints.com
     */
    
    // 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'))
            return;
        $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, true, '' );
        endif;
    }
    
    // JavaScript to update the totals on state selection
    add_action( 'wp_footer', 'ecommercehints_update_checkout_totals' );
    function ecommercehints_update_checkout_totals() { ?>
    <script>
        jQuery( function( $ ) {
        $( 'form.checkout' ).on( 'change', 'select[name^="billing_state"]', function() {
            $( 'body' ).trigger( 'update_checkout' );
        });
    });
    </script>
    <?php }
    
    Login or Signup to reply.
  2. I found this code at Xadapter.com. It adds the $.27 fee when the delivery address is in CO without involving the shipping method.

    /**
     * Add a standard $ value surcharge to transactions delivering a product to Colorado / checkout
     */
    add_action( 'woocommerce_cart_calculate_fees','xa_custom_surcharge' );
    function xa_custom_surcharge() {
        global $woocommerce;
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
        $state      = array('CO');
        $surcharge  = .27;
        if ( in_array( WC()->customer->shipping_state, $state ) ) {
            $woocommerce->cart->add_fee( 'Colorado Retail Delivery Fee', $surcharge, false, '' );
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search