Last active
March 13, 2020 10:32
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can I change this code to charge a % based fee for people who ship to california