Quote requests have one path through the server, whatever sends them: the configurator's own window, a headless front end, or your own code. A request is validated, stored according to the shop's settings, and emailed, the same way each time.
For setting them up as a shop manager, see Quote requests. The hooks are listed in Quote request hooks.
In the browser: PC.fe.quote
assets/js/quote-request.js loads on configurator pages when quote requests are enabled. It works without its window, so a front end of your own can use it as is.
| Method | Returns | Purpose |
|---|---|---|
PC.fe.quote.is_enabled() | bool | Whether quote requests are on |
PC.fe.quote.get_schema( product_id ) | Promise | The form fields, whether a picture is needed, and the values of a signed-in customer |
PC.fe.quote.validate_fields( values, schema ) | object | Field errors, keyed by field id |
PC.fe.quote.request( options ) | Promise | Validate the configuration, take a token, and send the request |
PC.fe.quote.get_mode() | string | The button placement for the current product |
request() takes fields (values keyed by field id), and optionally quantity, image ('auto' captures the 3D viewer; a Blob or data URL is used as is), captcha and show_errors. It resolves with the request's id, reference, store and the success message, or rejects with an error carrying a code, plus field_errors or configuration_errors when something needs fixing.
PC.fe.quote.request( {
fields: { name: 'Ada Lovelace', email: 'ada@example.com', message: 'Delivery in June?' }
} ).then( function( result ) {
console.log( 'Sent', result.reference );
} ).catch( function( error ) {
console.log( error.code, error.field_errors );
} );
Over REST
| Route | Method | Purpose |
|---|---|---|
/wp-json/mkl_pc/v1/quote-requests/schema?product_id= | GET | The fields to ask for, capture_image, and values for a signed-in customer |
/wp-json/mkl_pc/v1/quote-requests | POST | Send a request |
A request needs a one-time token: POST { "purpose": "quote_request_send", "product_id": 123 } to /wp-json/mkl_pc/v1/frontend-action-token first, and send the token you get with the request. The body takes product_id, variation_id, quantity, configuration (the configurator's payload, as JSON or an array), fields, image (a PNG data URL, for 3D products), lang and token. With files, send it as multipart, with these values as JSON in a request field.
A visitor can send 10 requests an hour. Invalid fields are answered with a 400 and data.field_errors.
In PHP: mkl_pc_create_quote_request()
For integrations that collect requests their own way, such as a form plugin or an import. It takes the same arguments as the REST body, without the token or the rate limit, and returns the \MKL\PC\Quote_Request, or a WP_Error.
$request = mkl_pc_create_quote_request( [
'product_id' => 123,
'configuration' => $payload,
'fields' => [ 'name' => 'Ada Lovelace', 'email' => 'ada@example.com' ],
] );
if ( ! is_wp_error( $request ) ) {
error_log( $request->reference );
}
Where requests are kept
mkl_pc( 'quotes' )->get_store() is the store chosen in the settings. A store implements \MKL\PC\Quote_Store; add your own with the mkl_pc/quote_request/stores filter, for example to send requests to a CRM.
A PDF of the quote
Core makes no PDF itself. A plugin provides one by returning a \MKL\PC\Quote_PDF_Provider from the mkl_pc/quote_request/pdf_provider filter: get_mode() says where the PDF goes (none, quote or all) and render( $request, $args ) returns the PDF's content. Save your design is one. Core attaches it to the emails and serves the downloads.
Templates
| Template | Overridden in |
|---|---|
The customer page: quotes.php, quote.php, quote-answer.php, quote-lookup.php, quote-not-found.php | yourtheme/product-configurator/quotes/ |
The emails: quote-request.php, quote-request-details.php, quote-request-answer.php, quote-request-lookup.php, and their plain/ versions | yourtheme/product-configurator/emails/ |