Gatemi Per-Product Shipping Developer Reference

The free edition applies no filters or actions of its own. Everything under Filters and Actions is the full edition's.

Filters — Full edition

gmps_product_cost

One product's shipping cost, after the plugin has decided it.

Argument Type
$costs array{first:float,extra:float}|null The cost, or null for "nobody has said"
$product WC_Product The product or variation in the cart

Return an array with both first and extra to price the product. Return anything else (including null) and the product is unpriced, which stops the whole package being quoted. Returning null is not the same as returning zero.

// Gift cards ship free, whatever the product says.
add_filter( 'gmps_product_cost', function ( $costs, $product ) {
	if ( has_term( 'gift-cards', 'product_cat', $product->get_parent_id() ?: $product->get_id() ) ) {
		return array( 'first' => 0.0, 'extra' => 0.0 );
	}
	return $costs;
}, 10, 2 );

The filter runs for every line in a shipping package and for the missing-cost report, so a product priced here drops off the report too.

gmps_settings

The merged settings array (after defaults), every time it is read. Must return an array.

// A higher free-delivery threshold during a promotion.
add_filter( 'gmps_settings', function ( $settings ) {
	$settings['free_over'] = '150';
	return $settings;
} );

gmps_modules

The ordered list of modules the plugin boots. For advanced use only.

gmps_license_api_url, gmps_update_cache_ttl

The gatemi.com licensing endpoint (for staging mirrors) and how long the update payload is cached, in seconds.

Actions — Full edition

gmps_booted

Fires once the plugin's modules have booted, with the service container.

The shipping method

Method id gmps_per_product (both editions)
Class GatemiPerProductShippingShippingMethod (full), GMPSF_Method (free)
Supports shipping-zones, instance-settings, instance-settings-modal
Instance settings title, tax_status
Rate tax calc_tax => per_order

The class is registered through woocommerce_shipping_methods and loaded on woocommerce_shipping_init. The method adds no rate at all when the package is unquotable. It does not hook woocommerce_package_rates.

Storage

Where Key Edition
Option gmps_settings — fallback_first, fallback_extra, minimum, maximum, free_over (all strings; empty means unset) Both (free reads the first two)
Product / variation meta _gmps_cost Both (free reads it on the product only)
Product / variation meta _gmps_extra Both
Shipping-class term meta _gmps_class_cost, _gmps_class_extra Full
Option gmps_license Full
Transient gmps_update_payload Full
Cron gmps_license_check Full

No database tables, no order meta, no storefront scripts.

Setting a cost in code

Write the meta directly, then clear WooCommerce's shipping cache, because a direct meta write does not fire the hooks that clear it.

update_post_meta( $product_id, '_gmps_cost', '4.00' );
update_post_meta( $product_id, '_gmps_extra', '1.50' ); // Omit for "same as the first".
WC_Cache_Helper::get_transient_version( 'shipping', true );

Store amounts as plain numbers with a dot. Delete _gmps_cost (and _gmps_extra) to mark a product as unpriced; do not store an empty string alongside a value in _gmps_extra.

Cache clearing

The plugin bumps WooCommerce's shipping transient version on woocommerce_update_product, on update_option_gmps_settings and (full edition) on updated_term_meta for the two shipping-class keys.

Shopping Cart
Scroll to Top