1. Home
  2. Docs
  3. WooCommerce EAN Payment Gateway
  4. I want to add a handling fee for EAN Payments

I want to add a handling fee for EAN Payments

As EAN Payments require manual handling, you may wish to add a fee to the order.

To do so add the following code to you functions.php file in the active theme.

<?php
if ( class_exists( 'WooCommerce' ) ) {
    add_action( 'woocommerce_cart_calculate_fees', 'yanco_ean_calculate_totals' );
    function yanco_ean_calculate_totals( ) {
		$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
	  $current_gateway = '';
    $fee_title = __('EAN Handling Fee', 'woocommerce-ean-payment-gateway'); // Change the title to fit your needs
    $ean_handling_fee = 50; // Change the value to the amount you want to charge
    $fee_tax_class = 'zero rate'; // Change this to the tax class you wish to use for the fee
		if ( ! empty( $available_gateways ) ) {
	        // Chosen Method
	        if ( isset( WC()->session->chosen_payment_method ) && isset( $available_gateways[ WC()->session->chosen_payment_method ] ) ) {
				$current_gateway = $available_gateways[ WC()->session->chosen_payment_method ];
	        } elseif ( isset( $available_gateways[ get_option( 'woocommerce_default_gateway' ) ] ) ) {
	            $current_gateway = $available_gateways[ get_option( 'woocommerce_default_gateway' ) ];
	        } else {
	            $current_gateway = current( $available_gateways );
	        }
	    }
		if ( $current_gateway->id == 'yanco_wc_ean_payment_gateway' ) {
			WC()->cart->add_fee( $fee_title, $ean_handling_fee, true, $fee_tax_class );
		}
    }
}

You’ll have to change the following:

The text EAN Handling Fee in line 6, to the desired text for the handling fee

$fee_title = __(‘EAN Handling Fee‘, ‘woocommerce-ean-payment-gateway’);

The number 50 in line 7, to the desired value for the handling fee

$ean_handling_fee = 50;

I want to add / remove VAT for the handling fee

To add VAT to the handling fee, change line 25 to

WC()->cart->add_fee( $fee_title, $ean_handling_fee, true, $fee_tax_class );

To remove VAT from the handling fee, change line 25 to

WC()->cart->add_fee( $fee_title, $ean_handling_fee, false, $fee_tax_class );

Was this article helpful to you? Yes No

How can we help?