View Categories

Payment Gateways by Shipping Developer Reference

This reference covers the filter, option keys and functions in Payment Gateways by Shipping Method for WooCommerce for developers who want to extend the shipping method list or manage rules with code. Store owners can configure everything at WPFactory > Payment Gateways by Shipping (also reachable at WooCommerce > Settings > Payment Gateways by Shipping) without code.

Filter: alg_wc_pgbsm_shipping_methods_settings_options #

Changes the shipping methods offered in every gateway field on the settings page.

Parameter Type Description
$shipping_methods array Method type mode: method ID to method title. Shipping instance mode: instance ID to “Zone name: Method title”.
$use_shipping_instance bool Whether Use shipping instances is enabled.

Example: add a method ID that WooCommerce does not list, so it can be selected in method type mode.

add_filter( 'alg_wc_pgbsm_shipping_methods_settings_options', function ( $shipping_methods, $use_shipping_instance ) {
	if ( ! $use_shipping_instance ) {
		$shipping_methods['my_custom_method'] = 'My custom method';
	}
	return $shipping_methods;
}, 10, 2 );

WooCommerce hooks used #

Hook Type Priority Purpose
woocommerce_available_payment_gateways filter PHP_INT_MAX Removes gateways whose rule does not match the chosen shipping method.
woocommerce_before_calculate_totals action 1 Clears the chosen payment method when Reset chosen payment method is enabled and the method is unavailable.

The plugin also applies the core woocommerce_cart_needs_shipping filter to decide whether rules apply.

Option keys #

Option Value
alg_wc_pgbsm_use_shipping_instance yes or no
alg_wc_pgbsm_enable_{gateway_id} Array of shipping method IDs, for example array( 'flat_rate', 'free_shipping' )
alg_wc_pgbsm_enable_instance_{gateway_id} Array of shipping method instance IDs as strings, for example array( '3', '7' )
alg_wc_pgbsm_reset_payment_method_on_totals yes or no

Example: allow Cash on delivery only for Flat rate and Free shipping in method type mode.

update_option( 'alg_wc_pgbsm_enable_cod', array( 'flat_rate', 'free_shipping' ) );

Matching logic #

  • In method type mode a chosen rate such as flat_rate:3 matches when it starts with a saved method ID such as flat_rate.
  • In shipping instance mode the number after the colon in the rate ID is compared with the saved instance IDs. Rates of Table Rate Shipping by WebFactory (jem_table_rate_) are read from the fourth underscore segment.
  • If the cart needs shipping and there is not exactly one unique chosen method, restricted gateways are removed.

Functions #

Function Returns
alg_wc_pgbsm() The main plugin instance.
alg_wc_pgbsm()->core->check_if_enabled_for_methods( $gateway_key, $enable_for_methods ) true if the current cart’s shipping method matches the given list.

Need a hand? Our team answers every ticket on the Payment Gateways by Shipping support forum.