Developers can change the location that Conditional Payment Methods by 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 for the full list.
Need a hand? Our team answers every ticket on the Payment Methods by Location support forum.