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 WooCommerce: Add Shipping Surcharge for Specific States

WooCommerce Snippet: Add Shipping Fee for Non-Continental States


/**
 * @snippet       Add Shipping Fee for Non-Continental States
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=19954
 * @author        Rodolfo Melogli
 * @compatible    WC 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_add_cart_fee' );

function bbloomer_add_cart_fee() {
$noncontinental = array('AK','HI');
if( in_array( WC()->customer->shipping_state, $noncontinental ) ) {
 $surcharge = 0.05 * WC()->cart->shipping_total; // 5% surcharge based on shipping cost
 WC()->cart->add_fee( __('Non-continental Shipping', 'woocommerce'), $surcharge );
}
}

Share:

Leave a Reply