-
-
Save amirulasyraf88/e19da4249effc7786dbae0eaaf456e64 to your computer and use it in GitHub Desktop.
Add percentage based fee to WooCommerce cart
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
<?php | |
add_action( 'woocommerce_cart_calculate_fees','endo_handling_fee' ); | |
function endo_handling_fee() { | |
global $woocommerce; | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
$subtotal = $woocommerce->cart->subtotal; | |
$fee_percentage = 0.1; // 10 percent | |
$fee = number_format( round( $subtotal * $fee_percentage, 2 ), 2 ); // rounded to two decimal places to match currency formatting | |
$woocommerce->cart->add_fee( 'Handling', $fee, true, 'standard' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment