Created
May 14, 2021 04:52
-
-
Save wbcomdev/7608f9dbfa4005ccf929a7c0c7da28ce 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. | |
| * change the $percentage to set the surcharge to a value to suit. | |
| */ | |
| function wb_woocommerce_custom_surcharge() { | |
| global $woocommerce; | |
| if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { | |
| return; | |
| } | |
| $percentage = 0.01; | |
| $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage; | |
| $woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' ); | |
| } | |
| 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