Last active
July 15, 2021 14:32
-
-
Save jorpdesigns/ba35de2aafebf15edc067207844f0c04 to your computer and use it in GitHub Desktop.
Snippet to add fee to WooCommerce cart
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
<?php | |
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); | |
function woocommerce_custom_surcharge( $cart ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
// ADD FLAT RATE FEE | |
$surcharge = 5; // Replace 5 with your fee | |
// ADD FEE AS PERCENTAGE OF CART TOTAL | |
$percentage = 0.15; // Replace 0.15 with your percentage | |
$surcharge = ceil( $cart->cart_contents_total * $percentage ); | |
$cart->add_fee( 'Fee Label', $surcharge, true, '' ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment