Home » WooCommerce: Add Shipping Fee for Non-Continental States

WooCommerce: Add Shipping Fee for Non-Continental States

by Tutor Aspire

Today we take a look at the WooCommerce Checkout page and specifically at how to add a Custom Extra Fee for Non-Continental US States.

You can do the exact same thing for a non-US State, as long as customers will feel comfortable in paying extra!

WooCommerce: Add Shipping Surcharge for Specific States
WooCommerce: Add Shipping Surcharge for Specific States

PHP Snippet: Add Shipping Fee for Non-Continental States @ WooCommerce Checkout

/**
 * @snippet       Add Shipping Fee for Non-Continental States
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://tutoraspire.com
 */

add_action( 'woocommerce_cart_calculate_fees', 'tutoraspire_add_cart_fee_for_states' );

function tutoraspire_add_cart_fee_for_states() {
   $noncontinental = array( 'AK', 'HI' ); // ARRAY OF STATE CODES
   if ( in_array( WC()->customer->get_shipping_state(), $noncontinental ) ) {
      $surcharge = 0.05 * WC()->cart->shipping_total; // 5% surcharge based on shipping cost
      WC()->cart->add_fee( 'Non-continental Shipping', $surcharge );
   }
}

You may also like