Gatemi Checkout Fees Developer Reference

The free edition applies no filters of its own. Everything under Filters is the full edition's. The storage below is shared by both.

Filters — Full edition

gmfe_charges

Every charge a cart has earned, just before they are added with WC_Cart::add_fee().

Argument Type
$charges array A list of id, label, amount, taxable, tax_class. Insurance has the id insurance.
$context GatemiCheckoutFeesFeesCartContext What the rules were judged on

CartContext has public goods, shipping, tax, items, country, payment_method, shipping_methods, roles and product_ids, plus total(), goods_and_shipping(), categories() and shipping_classes().

// Never surcharge orders over 1,000.
add_filter( 'gmfe_charges', function ( $charges, $context ) {
	if ( $context->total() <= 1000 ) {
		return $charges;
	}
	return array_values( array_filter( $charges, function ( $c ) {
		return 'card-surcharge' !== $c['id'];
	} ) );
}, 10, 2 );

Return something that is not an array and the plugin keeps its own list.

gmfe_condition_types and gmfe_evaluate_condition

Add a condition type of your own. gmfe_condition_types filters the vocabulary the rule editor renders from: an array keyed by type id, each with label and value (number or list). gmfe_evaluate_condition answers a type the plugin does not know.

gmfe_evaluate_condition argument Type
$matches bool false — an unknown condition never matches unless you say so
$condition array type and value
$context CartContext The cart
add_filter( 'gmfe_condition_types', function ( $types ) {
	$types['weekend'] = array( 'label' => 'It is the weekend', 'value' => 'number' );
	return $types;
} );

add_filter( 'gmfe_evaluate_condition', function ( $matches, $condition ) {
	if ( 'weekend' !== $condition['type'] ) {
		return $matches;
	}
	return in_array( wp_date( 'N' ), array( '6', '7' ), true );
}, 10, 2 );

If your code stops answering, the type is still stored and the rule simply stops charging.

gmfe_rules

The rules after they are read and normalised.

gmfe_settings

The settings array after defaults are merged in.

Licensing and boot

  • gmfe_license_api_url — the licence server's base URL.
  • gmfe_update_cache_ttl (default 12 hours), gmfe_update_retry_ttl (default 15 minutes) and gmfe_sync_cache_ttl (default 12 hours) — cache lifetimes in seconds, never below 60.
  • gmfe_modules — the list of modules booted.

Actions — Full edition

  • gmfe_booted — fires after every module has booted; receives the plugin's container.

WooCommerce hooks used

Hook Priority Does
woocommerce_cart_calculate_fees 20 Adds the fees; skipped on a non-AJAX admin request
woocommerce_cart_totals_before_order_total 10 Prints the insurance box on the cart
woocommerce_review_order_before_order_total 10 Prints it on the checkout
woocommerce_cart_updated 10 Reads the box from the cart form (POST only)
woocommerce_checkout_update_order_review 10 Reads the box from the checkout refresh
woocommerce_checkout_create_order 10 Writes the insurance record
woocommerce_store_api_checkout_update_order_from_request 10 Writes the insurance record on a Checkout-block order (and clears a stale one from a reused draft)
woocommerce_blocks_loaded 10 Registers the box's Store API cart data and its update callback (namespace gatemi-checkout-fees)
render_block_woocommerce/cart, render_block_woocommerce/checkout 10 Enqueue the block insurance script, only while cover is offered
woocommerce_thankyou, woocommerce_cart_emptied 10 Forget the insurance choice

Options

Option Edition What it holds
gmfe_rules both The list of fee rules
gmfe_settings both The insurance settings
gmfe_license Full edition Licence key and state

The rule shape

array(
	'id'         => 'card-surcharge',   // made from the label, then kept
	'label'      => 'Card surcharge',   // empty label = rule removed
	'kind'       => 'percent',          // 'fixed' | 'percent'
	'base'       => 'total',            // 'goods' | 'goods_shipping' | 'total'
	'amount'     => 1.4,                // signed; negative is a discount
	'taxable'    => false,
	'tax_class'  => '',
	'conditions' => array(
		array( 'type' => 'payment_method', 'value' => array( 'stripe' ) ),
	),
	'enabled'    => true,
)

Rules are normalised on read as well as on save, so a rule written by hand or imported is checked the same way.

Session and posted field

  • Session key gmfe_insured — yes or no.
  • Posted field gmfe_insure — the tick box, on the cart form and the checkout form.

Order meta

Key Value
_gmfe_insured yes when the order was insured
_gmfe_insured_amount What the cover cost, as charged
_gmfe_insured_value The goods it covered

Written through the order object, so HPOS and the legacy store behave the same. Neither edition removes them on uninstall.

$order = wc_get_order( $order_id );
if ( 'yes' === $order->get_meta( '_gmfe_insured' ) ) {
	$cover = (float) $order->get_meta( '_gmfe_insured_value' );
}

Cron — Full edition

  • gmfe_license_check — twice daily, only once a licence key is entered.

CSS

No storefront stylesheet is loaded. The insurance row is a <tr> in the totals table with these classes:

Class Free edition Full edition
Row gmfef-insurance gmfe-insurance
Label gmfef-insurance-label gmfe-insurance-label
Note gmfef-insurance-note gmfe-insurance-note
Shopping Cart
Scroll to Top