Shared between the editions
gmrf_fields (option)
The field list, keyed by field key. Each field:
'gmrf_company' => array(
'key' => 'gmrf_company',
'label' => 'Company name',
'placeholder' => '',
'type' => 'text', // text, checkbox (both); textarea, select, radio, email, tel, number, date (full)
'options' => array(), // key => label, for select and radio
'priority' => 0, // lower first
'required' => false,
'enabled' => true,
'class' => '',
'show_admin' => true, // on the profile
'editable' => false, // on My Account → Account details
'show_if' => '', // another field's key
'show_value' => '', // the value it must hold; '' = any
),
Keys always begin gmrf_. The field list is normalised every time it is read, not only when saved.
User meta
_gmrf_ + the field key — for gmrf_company, the meta key is _gmrf_gmrf_company. An unanswered field has no meta at all.
$company = get_user_meta( $user_id, '_gmrf_gmrf_company', true );
Hooks used
| Hook | Use |
|---|---|
woocommerce_register_form |
Print the fields on My Account, with the hidden marker gmrf_form |
woocommerce_after_checkout_registration_form |
Print them in the classic checkout's "create an account" box |
woocommerce_registration_errors |
Required-field errors (gmrf_required_{key}; full edition also gmrf_invalid_{key} for a rejected value) — only when gmrf_form was posted |
woocommerce_created_customer |
Store the answers — only when gmrf_form was posted |
show_user_profile, edit_user_profile |
The Registration details section |
personal_options_update, edit_user_profile_update |
Save it (nonce gmrf_profile / field gmrf_profile_nonce); only for a user who can edit_users, and only the keys that were posted |
wp_privacy_personal_data_exporters, wp_privacy_personal_data_erasers |
Register exporter and eraser, id gatemi-registration-fields |
CSS classes
Each field is printed by woocommerce_form_field() with the classes gmrf-field and gmrf-field--{key}, inside WooCommerce's usual form-row markup:
.gmrf-field--gmrf_company input { text-transform: uppercase; }
Free edition
The free edition applies no filters or actions of its own. Its admin form posts gmrf_fields[n][label|key|type|required] with the nonce gmrff_save_fields.
Full edition
Filters
| Filter | Argument | Purpose |
|---|---|---|
gmrf_fields |
$fields |
The stored field configuration, after normalisation |
gmrf_field_types |
$types |
The type vocabulary — add your own |
gmrf_settings |
$settings |
users_column, users_column_field, capability |
gmrf_modules |
$modules |
The module list booted |
gmrf_license_api_url |
$url |
Licence API base URL (staging) |
gmrf_update_cache_ttl |
$seconds |
Update payload cache |
Each type is array( 'label' => …, 'wc_type' => …, 'has_options' => bool ), where wc_type is what woocommerce_form_field() is asked to draw. A type you add is sanitised as plain text.
// A "URL" field type, drawn as WooCommerce's url input.
add_filter( 'gmrf_field_types', function ( $types ) {
$types['url'] = array( 'label' => 'Web address', 'wc_type' => 'url', 'has_options' => false );
return $types;
} );
// Add a field from code.
add_filter( 'gmrf_fields', function ( $fields ) {
$fields['gmrf_vat'] = array_merge( $fields['gmrf_vat'] ?? array(), array(
'key' => 'gmrf_vat', 'label' => 'VAT number', 'type' => 'text',
) );
return $fields;
} );
A field added through gmrf_fields is not normalised for you; give it every key in the shape above.
Actions
gmrf_booted — after every module has booted; receives the service container.
More hooks used
| Hook | Use |
|---|---|
woocommerce_edit_account_form |
Editable fields on Account details |
woocommerce_save_account_details_errors |
Their required check |
woocommerce_save_account_details |
Save them |
manage_users_columns, manage_users_custom_column |
The Users column (gmrf_{key}), only with users_column on |
Storefront script
gmrf-form (assets/js/form.js) shows and hides conditional fields while the form is filled in, reading window.gmrfData.rules. It is a convenience; the server decides.
Other storage
| Item | Name |
|---|---|
| Settings | gmrf_settings |
| Licence | gmrf_license |
| Update cache | transient gmrf_update_payload |
| Cron | gmrf_license_check (only with a key) |
