Created
          February 19, 2017 05:28 
        
      - 
      
- 
        Save nielslange/b98e50e29acbd8f7b13cac4217692810 to your computer and use it in GitHub Desktop. 
    WooCommerce: Add a basic surcharge to all transactions
  
        
  
    
      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 a 1% surcharge to your cart / checkout | |
| * change the $percentage to set the surcharge to a value to suit | |
| * Uses the WooCommerce fees API | |
| * | |
| * Add to theme functions.php | |
| */ | |
| add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); | |
| function 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, '' ); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment