Advertisement
imnguyen

GACO: working grat

Feb 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1.  
  2. add_action( 'woocommerce_cart_calculate_fees', 'custom_fee_based_on_cart_total', 10, 1 );
  3. function custom_fee_based_on_cart_total( $cart_object ) {
  4.  
  5. if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
  6.  
  7. // The percetage
  8. $percent = 15; // 15%
  9. // The cart total
  10. $cart_total = $cart_object->cart_contents_total;
  11.  
  12. // The conditional Calculation
  13. $fee = $cart_total > 0.01 ? $cart_total * $percent / 100 : 0;
  14.  
  15. if ( $fee != 0 )
  16. $cart_object->add_fee( __( "Gratuity", "woocommerce" ), $fee, false );
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement