Created
May 14, 2021 04:57
-
-
Save wbcomdev/a51c9bf3cfadffbaefaef53d616191af to your computer and use it in GitHub Desktop.
This file contains hidden or 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 a 1% surcharge to your cart / checkout based on delivery country. | |
| * Taxes, shipping costs and order subtotal are all included in the surcharge amount. | |
| */ | |
| function wb_woocommerce_custom_surcharge() { | |
| global $woocommerce; | |
| if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { | |
| return; | |
| } | |
| $county = array( 'US' ); | |
| $percentage = 0.01; | |
| if ( in_array( $woocommerce->customer->get_shipping_country(), $county ) ) : | |
| $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage; | |
| $woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' ); | |
| endif; | |
| } | |
| add_action( 'woocommerce_cart_calculate_fees', 'wb_woocommerce_custom_surcharge' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment