Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_cart_calculate_fees', 'custom_fee_based_on_cart_total', 10, 1 );
- function custom_fee_based_on_cart_total( $cart_object ) {
- if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
- // The percetage
- $percent = 15; // 15%
- // The cart total
- $cart_total = $cart_object->cart_contents_total;
- // The conditional Calculation
- $fee = $cart_total > 0.01 ? $cart_total * $percent / 100 : 0;
- if ( $fee != 0 )
- $cart_object->add_fee( __( "Gratuity", "woocommerce" ), $fee, false );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement