1. Home
  2. Payment Gateway Based Fees and Discounts for WooCommerce
  3. Hooks and Filters Documentation

Hooks and Filters Documentation

The following is a list of all hooks and filters present in the plugin. Hooks and Filters allow developers to modify or extend the functionality of the Payment Gateway Based Fees and Discounts for WooCommerce plugin without directly editing core files.

How can I apply fees after calculating the discount price?

Hook:
alg_wc_checkout_fees_apply_fees_on_payment_amount:

Usage:

add_filter( 'alg_wc_checkout_fees_apply_fees_on_payment_amount', 'alg_wc_checkout_fees_apply_fees_on_payment_amount_callback' );

Parameters: None

Example:

add_filter( 'alg_wc_checkout_fees_apply_fees_on_payment_amount', 'alg_wc_checkout_fees_apply_fees_on_payment_amount_callback' );
function alg_wc_checkout_fees_apply_fees_on_payment_amount_callback(){
	return true;
}

How can I remove the “Tax Included” text on the checkout page?

Hook:
alg_wc_checkout_fees_hide_include_tax_text:

Usage:

add_filter( 'alg_wc_checkout_fees_hide_include_tax_text', 'alg_wc_checkout_fees_hide_include_tax_text_callback' );

Parameters: None

Example:

add_filter( 'alg_wc_checkout_fees_hide_include_tax_text', 'alg_wc_checkout_fees_hide_include_tax_text_callback' );
function alg_wc_checkout_fees_hide_include_tax_text_callback() {
    return true;
}

How can I set different fees for each payment gateway based on the countries?

Hook:
modify_fees_value_frontend, modify_fees_value_backend:

Usage:

add_filter( 'modify_fees_value_frontend', 'modify_fees_value_frontend', 10, 3 );

Parameters: 3

add_filter( 'modify_fees_value_backend', 'modify_fees_value_backend', 10, 4 );

Parameters: 4

Example:

function assign_value_for_country( $payment_gateway, $fee_type ) {
	switch ( $payment_gateway ) {
		case 'cod':
			if ( $fee_type == 'percent' ) {
				$data = array(
					'GB' => '2',
					'IN' => '4',
					'CA' => '6',
					'DE' => '8',
				);
			} elseif ( $fee_type == 'fixed' ) {
				$data = array(
					'GB' => '3',
					'IN' => '3',
					'CA' => '4',
					'DE' => '5',
				);
			}
			break;
		case 'bacs':
			if ( $fee_type == 'percent' ) {
				$data = array(
					'GB' => '5',
					'IN' => '10',
					'CA' => '15',
					'DE' => '20',
				);
			} elseif ( $fee_type == 'fixed' ) {
				$data = array(
					'GB' => '3',
					'IN' => '6',
					'CA' => '9',
					'DE' => '12',
				);
			}
			break;
	}
	return $data;
}


function modify_fees_value_frontend( $fee_value, $fee_type, $payment_gateway ) {
	$userlocation = get_user_country();
	$country_fees = assign_value_for_country( $payment_gateway, $fee_type );
	if ( array_key_exists( $userlocation, $country_fees ) ) {
		$fee_value = $country_fees[ $userlocation ];
	}
	return $fee_value;
}
add_filter( 'modify_fees_value_frontend', 'modify_fees_value_frontend', 10, 3 );


function modify_fees_value_backend( $fee_value, $fee_type, $payment_gateway, $order ) {
	$userlocation = $order->get_billing_country();
	$country_fees = assign_value_for_country( $payment_gateway, $fee_type );
	if ( array_key_exists( $userlocation, $country_fees ) ) {
		$fee_value = $country_fees[ $userlocation ];
	}
	return $fee_value;
}
add_filter( 'modify_fees_value_backend', 'modify_fees_value_backend', 10, 4 );


function get_user_country() {
	$location = WC_Geolocation::geolocate_ip();
	$country = $location['country'];
	return $country;
}

Was this article helpful to you? Yes No

How can we help?