The free edition applies no filters or actions of its own. The hooks under Filters and Actions are the full edition's. Storage is shared by both editions.
Storage
The plugin has no tables and writes no post, user or order meta. Two options hold everything.
gmct_catalogs
Catalogs keyed by id, in the merchant's order. Each catalog:
| Key | Type | |
|---|---|---|
id |
string |
sanitize_key(). The free edition's catalog is always catalog. |
name |
string |
Full edition. |
enabled |
bool |
Missing means true. |
roles |
string[] |
Role keys; guest for visitors not signed in. |
users |
int[] |
Full edition. User ids. |
products |
int[] |
Product ids. |
categories |
int[] |
product_cat term ids; children are included at read time. |
discount |
float|null |
Full edition. Percentage 0–100, or null. |
prices |
array<int,float> |
Full edition. Product id ⇒ price. |
A numeric or empty id is replaced by catalog-N; a duplicate id gets -2 appended. Normalisation runs on read as well as on save.
gmct_settings
| Key | Default | |
|---|---|---|
hide |
yes |
Remove restricted products from queries and 404 their pages. |
badge |
yes |
Full edition. |
badge_text |
Your price |
Full edition. |
message |
'' |
The add-to-cart refusal. |
structured |
yes |
Full edition. |
gmct_license (full edition) holds the licence state; the free edition's uninstall uses its presence to know the full edition was used.
WooCommerce hooks used
| Hook | Why |
|---|---|
woocommerce_is_purchasable, woocommerce_variation_is_purchasable |
Refuse a restricted product everywhere at once. |
woocommerce_add_to_cart_validation |
Refuse the addition with the message. |
woocommerce_check_cart_items |
Remove a restricted product already in a cart. |
pre_get_posts |
post__not_in and a product_cat NOT IN tax query on product queries (front end only). |
woocommerce_product_is_visible |
Hide from loops and widgets. |
get_terms |
Drop hidden categories from lists and menus (not term lookups for a specific object). |
template_redirect (8, 10) |
No-cache headers while in force; 404 on a restricted product page. |
woocommerce_get_variation_prices_hash |
Adds a gmct token (the customer's sorted catalog ids, or public) to the variation price cache key. |
woocommerce_product_get_price, …_variation_get_price, …_get_sale_price, …_variation_get_sale_price |
Full edition. Catalog prices. |
woocommerce_get_price_html |
Full edition. The badge. |
woocommerce_structured_data_product |
Full edition. Removes offers. |
Filters — Full edition
gmct_catalogs
The catalogs as read, after normalisation. Use it to add a catalog from code.
add_filter( 'gmct_catalogs', function ( $catalogs ) {
$catalogs['vip'] = array(
'id' => 'vip',
'name' => 'VIP',
'enabled' => true,
'roles' => array(),
'users' => array( 12, 48 ),
'products' => array( 301, 302 ),
'categories' => array(),
'discount' => 15.0,
'prices' => array(),
);
return $catalogs;
} );
A catalog added this way is not normalised, so give it the full shape.
gmct_user_catalogs
The catalog ids one customer belongs to.
| Argument | Type | |
|---|---|---|
$ids |
string[] |
Catalog ids |
$user_id |
int |
0 for a guest |
// Customers with an approved trade flag are in the "trade" catalog.
add_filter( 'gmct_user_catalogs', function ( $ids, $user_id ) {
if ( $user_id && get_user_meta( $user_id, 'my_trade_approved', true ) ) {
$ids[] = 'trade';
}
return $ids;
}, 10, 2 );
The answer is memoised per user for the rest of the request.
gmct_settings
The merged settings array on every read.
gmct_modules
The ordered module list. For tests and debugging.
Licensing
gmct_license_api_url, gmct_update_cache_ttl (12 hours), gmct_update_retry_ttl (15 minutes), gmct_sync_cache_ttl (12 hours).
Actions — Full edition
gmct_booted
Fires once modules have booted, with the service container. Service ids include settings, catalogs (the repository) and resolver.
add_action( 'gmct_booted', function ( $c ) {
$resolver = $c->get( 'resolver' );
// $resolver->may_see( $product_id, $user_id );
// $resolver->price_for( $product_id, $regular_price, $user_id );
// $resolver->catalogs_for_user( $user_id );
} );
CSS
| Class | Element |
|---|---|
.gmct-badge |
Full edition. The "Your price" <span> after the price. Uses currentColor; restyle it in your theme. |
The stylesheet (gmct) is only enqueued on pages where a badge was printed. The free edition prints nothing on the storefront.
Uninstall
- Full edition: deletes
gmct_settings,gmct_catalogs,gmct_license, the update transient and thegmct_license_checkcron event. - Free edition: deletes
gmct_settingsandgmct_catalogsonly whengmct_licensedoes not exist.
