---
title: Payment Methods by Location Developer Hooks
description: Change the customer location used by Payment Methods by Location with the alg_wc_gateways_by_location_get_location filter.
url: "https://wpfactory.com/docs/payments-by-location-developer-hooks/"
updated: "2026-09-27"
category: Developers
---

# Payment Methods by Location Developer Hooks

Developers can change the location that [Conditional Payment Methods by Location for WooCommerce](https://wpfactory.com/item/payment-gateways-by-customer-location-for-woocommerce/) checks for each customer with the `alg_wc_gateways_by_location_get_location` filter. The rules themselves are set at **WPFactory > Payment Gateways by Customer Location**; this filter only adjusts the customer value they are compared with.

## How gateways are filtered

The plugin hooks into `woocommerce_available_payment_gateways` at priority `PHP_INT_MAX`, so it runs after other plugins using that filter. For each enabled location type (country, state, city, postcode), it gets the customer's value and removes a gateway if the value is not in the gateway's Include list or is in its Exclude list. An empty customer value skips that type.

## Filter reference

| Filter | Arguments | Returns |
| --- | --- | --- |
| `alg_wc_gateways_by_location_get_location` | `$result` (string, the detected value), `$type` (`country`, `state`, `city` or `postcode`) | The value to compare. Return an empty string to skip that location type for the current request. |

Values passed to the filter: country is a two-letter code, state is a state code, city and postcode are upper-case strings.

## Example: ignore spaces in postcodes

Postcodes are matched exactly, so `SW1A 1AA` and `SW1A1AA` differ. This snippet strips spaces from the customer's postcode; enter your saved postcodes without spaces too.

```
add_filter( 'alg_wc_gateways_by_location_get_location', function ( $result, $type ) {
	if ( 'postcode' === $type ) {
		$result = str_replace( ' ', '', $result );
	}
	return $result;
}, 10, 2 );
```

## Example: skip city rules for logged-in administrators

```
add_filter( 'alg_wc_gateways_by_location_get_location', function ( $result, $type ) {
	if ( 'city' === $type && current_user_can( 'manage_options' ) ) {
		return '';
	}
	return $result;
}, 10, 2 );
```

## Options

All settings are standard WordPress options prefixed with `alg_wc_gateways_by_location_`. Include and Exclude values are arrays keyed by gateway ID. See the [settings reference](https://wpfactory.com/docs/payments-by-location-settings-reference/) for the full list.

Need a hand? Our team answers every ticket on the [Payment Methods by Location support forum](https://wpfactory.com/support/item/payment-gateways-by-customer-location-for-woocommerce/).

Related articles

- [Troubleshooting Payment Methods by Location](https://wpfactory.com/docs/payments-by-location-troubleshooting/)
- [Getting Started with Conditional Payment Methods by Location for WooCommerce](https://wpfactory.com/docs/payments-by-location-getting-started/)
- [How to Restrict Payment Methods by Postcode or ZIP Code in WooCommerce](https://wpfactory.com/docs/payments-by-location-postcode/)
- [How to Restrict Payment Methods by City in WooCommerce](https://wpfactory.com/docs/payments-by-location-city/)
- [How to Restrict Payment Methods by State in WooCommerce](https://wpfactory.com/docs/payments-by-location-state/)
