How to add a surcharge based on the delivery of state?

Write some new code for it…I'll do it for you this time:

add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
    global $woocommerce;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
        return;
    }

    $state = $woocommerce->customer->get_shipping_state();

    if ( $state == 'ME' ) {
        $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * 0.01;
        $woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, 'standard' );
    } elseif ( $state == 'OH' ) {
        // Do something else
    } elseif ( in_array( $state, array('FL', 'CA') ) ) {
        // Even something else
    }
}
This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.