Developer guide
Architecture, stored data, endpoints, templates, JavaScript events and examples. All hooks are listed in the Hooks reference.
Architecture
| Free | Pro | |
|---|---|---|
| Namespace | Siteryn\SiterynRequestAQuote | SiterynPro\SiterynRequestAQuote |
| Boot | Plugin::run() on plugins_loaded once PHP, WordPress and WooCommerce are confirmed, then siteryn_raq_loaded | Boots on siteryn_raq_loaded, fires siteryn_raq_pro_loaded; rules, workflow, PDFs, emails and negotiation run only while licensed (siteryn_raq_pro_features_loaded) |
| Extension API | Plugin::API_VERSION = 1.0 | Requires Free 1.0.0 and API 1.0 |
| Handles | siteryn-raq (storefront CSS and JS), admin siteryn-raq-admin | siteryn-raq-pro (storefront CSS and target-price JS), siteryn-raq-pro-admin, plus a rules script on the Quote Rules tab |
| Settings page | admin.php?page=siteryn-request-a-quote, tabs general, button, quote_page, form, emails, quotes, go_premium, system_status | Same page, tabs pro_rules, pro_workflow, pro_negotiation, pro_pdf, pro_emails, pro_license |
| Capability | manage_woocommerce for the settings page, quote requests and every admin action | |
Free's admin is built from a field registry: Pro adds its tabs through siteryn_raq_settings_sections and siteryn_raq_settings_fields and saves into its own option registered with Settings::register_addon_option().
Data stored
| Where | Key | Contents |
|---|---|---|
| Options | siteryn_raq_settings | Free settings |
siteryn_raq_version · siteryn_raq_page_id | Installed version · the automatically created quote page | |
siteryn_raq_pro_settings · siteryn_raq_pro_rules · siteryn_raq_pro_version | Pro settings · quote rules (not autoloaded) · Pro version | |
siteryn_raq_pro_license_key · _status · _update | Pro license data | |
| Post type | siteryn_raq_quote | Quote requests (not public, no REST). Statuses siteryn-raq-new; Pro adds siteryn-raq-review, -sent, -accepted, -rejected (Declined), -expired, -ordered |
| Post meta | _siteryn_raq_customer, _customer_id, _email, _message, _items, _fields, _currency, _locale, _language | The request: contact details, items snapshot (product, variation, name, attributes, SKU, quantity, price, data, meta), extra form fields |
_siteryn_raq_pro_offer, _pro_access_hash, _pro_notes, _pro_order_id | Pro: offer (prices, valid until, message, sent time), hashed customer link key, history (up to 200 entries), linked order | |
| User meta | {prefix}siteryn_raq_items | A logged-in customer's quote list |
| WooCommerce session | siteryn_raq_items, siteryn_raq_form_flash, siteryn_raq_last_quote | A guest's list; form errors for the no-JS reload; the last sent request (for the thank-you page) |
| Order meta | _siteryn_raq_quote_id | Pro: the quote an order was created from (created_via = siteryn-request-a-quote) |
| Transients | siteryn_raq_rl_*, siteryn_raq_done_*, siteryn_raq_outdated_templates | Rate limit counters (1 hour), duplicate-submission guard (1 day), outdated-template cache (1 day) |
| Cron | siteryn_raq_pro_expire_offers (daily) · siteryn_raq_pro_license_refresh (twice daily) | Pro only |
Endpoints
Storefront requests use WooCommerce's ?wc-ajax= endpoint, are POST only and check the siteryn_raq_quote_list nonce (a fresh nonce comes back with every response). The URLs are in window.siterynRaq.endpoints.
| Action | Type | Does |
|---|---|---|
siteryn_raq_add_item | wc-ajax | Add product_id, quantity, variation_id, attribute_* |
siteryn_raq_update_item · siteryn_raq_remove_item | wc-ajax | Set quantity of key (0 removes) · remove key |
siteryn_raq_get_list | wc-ajax | The list state (count, total quantity, items) |
siteryn_raq_submit_quote | wc-ajax | Send the request; returns the number and the thank-you HTML |
siteryn_raq_pro_item_meta | wc-ajax (Pro) | Save a line's target_price |
siteryn_raq_action = add/update/remove/submit | POST field | The same actions without JavaScript, with the _siteryn_raq_nonce field |
siteryn_raq_save_settings · siteryn_raq_pro_save_rules · siteryn_raq_pro_quote_action · siteryn_raq_pro_license | admin-ajax | Save a settings tab · save rules · save/send offer, set status, convert, add note · license actions |
siteryn_raq_reset_settings · siteryn_raq_pro_pdf | admin-post | Reset a tab · download a request's PDF |
Query arguments on the quote page: quote-received (thank-you after a no-JS send, only for the session that sent it), and with Pro raq-view + key (customer's quote), raq-pdf (customer PDF download) and raq-response (accept/decline result).
Templates
Copy a template to your theme and edit the copy. An admin notice and System Status tell you when a copy is older than the plugin's @version.
| Template | Theme path |
|---|---|
add-to-quote-button.php, quote-list.php, quote-form.php, quote-empty.php, quote-success.php, quote-login-required.php, quote-count.php | yourtheme/siteryn-request-a-quote/ |
emails/siteryn-raq-admin-new-quote.php, emails/siteryn-raq-customer-quote-received.php, emails/siteryn-raq-quote-details.php and their emails/plain/ versions | yourtheme/woocommerce/emails/… |
Pro quote-view.php (customer's quote) | yourtheme/siteryn-request-a-quote/pro/quote-view.php |
Pro emails/siteryn-raq-pro-customer-quote-sent.php, emails/siteryn-raq-pro-admin-quote-response.php, emails/siteryn-raq-pro-offer-table.php (+ plain) | yourtheme/woocommerce/emails/… |
Templates receive their variables as documented in each file's header. siteryn_raq_template_args filters them, and siteryn_raq_locate_template can point to another file.
JavaScript
Event on document | When |
|---|---|
siteryn-raq:ready | The storefront script has started |
siteryn-raq:updated | After any list change; event.detail is the response data (count, quantity, items, message…) |
siteryn-raq:submitted | After a request was sent; event.detail includes quoteId and number |
siteryn_raq_pro_license_changed (admin) | The license was activated or deactivated on the settings page; detail.active |
window.siterynRaqApi exposes send( action, body ) (queued requests, one at a time), announce( text ), showMessage(), setBusy() and applyState( data ). Configuration is in window.siterynRaq, filterable with siteryn_raq_script_config.
document.addEventListener( 'siteryn-raq:submitted', function ( event ) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push( { event: 'quote_request', quote: event.detail.number } );
} );
CSS
Storefront markup uses .siteryn-raq classes. Your color and radius settings are printed as CSS variables on .siteryn-raq and .siteryn-raq-scope: --siteryn-raq-button-bg, -button-text, -button-border, -button-hover-bg, -button-hover-text, -button-radius, --siteryn-raq-accent and -accent-text. Add more with siteryn_raq_css_vars. The quote page's <body> gets siteryn-raq-quote-page; a hidden price uses .siteryn-raq-pro-hidden-price.
Adding a form field
Fields are arrays with type (text, email, tel, textarea, number, date, select with choices, checkbox), label, required, width (half/full), max_length, placeholder and autocomplete. Extra fields are validated, saved with the request, and shown under Additional details and in the emails.
add_filter( 'siteryn_raq_form_fields', function ( $fields ) {
$fields['postcode'] = array(
'type' => 'text',
'label' => 'Delivery postcode',
'required' => true,
'width' => 'half',
);
return $fields;
} );
More examples
add_filter( 'siteryn_raq_quote_number', function ( $number ) {
return 'Q-' . $number;
} );
add_action( 'siteryn_raq_quote_created', function ( $quote_id, $quote ) {
wp_remote_post( 'https://example.com/hook', array(
'body' => array( 'number' => $quote->get_number(), 'email' => $quote->get_customer_email() ),
) );
}, 10, 2 );
add_filter( 'siteryn_raq_max_list_items', function () {
return 200;
} );