Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active March 13, 2020 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xadapter/8d90879f0db1988e464e69cea4cbe157 to your computer and use it in GitHub Desktop.
Save xadapter/8d90879f0db1988e464e69cea4cbe157 to your computer and use it in GitHub Desktop.
Snippet to add an additional fee to the WooCommerce shipping cost based on state. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
add_action( 'woocommerce_cart_calculate_fees','xa_custom_surcharge' );
function xa_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$state = array('MH');
$surcharge = 10;
if ( in_array( WC()->customer->shipping_state, $state ) ) {
$woocommerce->cart->add_fee( 'Additional Charge', $surcharge, true, '' );
}
}
@YLXTechnologies
Copy link

Can I change this code to charge a % based fee for people who ship to california

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment