For developers
Filters, actions and a small JavaScript object let you extend the designer without changing the plugin's files. The full reference is the file docs/hooks.md in the plugin's source repository.
All hooks start with vst_. The constant VST_API_VERSION (currently 1) goes up when the hook set or the PHP API changes in a way that breaks add-ons. Option and meta keys with the prefixes vsticker_, _vsticker_ and _vst_ belong to the plugin; an add-on uses its own prefix.
Start an add-on
add_action('vst_loaded', function () {
if (!defined('VST_API_VERSION') || VST_API_VERSION < 1) {
return; // too old: show your own admin notice
}
My_Addon::init();
});
vst_loaded fires at the end of the plugin's plugins_loaded callback. It does not fire when WooCommerce or the required PHP version is missing.
Pricing
The price a customer pays is always computed on the server. The designer shows the same formula in JavaScript. An add-on that changes the price registers both the PHP filter and the JavaScript filter, with the same logic, so the customer sees the price they pay.
| Hook | Type | Purpose |
|---|---|---|
vst_calculated_price | filter | Adjust the price per piece after discount, minimum, extra colours and rush, before rounding. |
VSTPricing.addFilter('price', fn) | JS | The same adjustment in the browser, with an optional label for the breakdown line. |
VSTPricing.addFilter('lines', fn) | JS | Change the price breakdown lines. Lines never change the price. |
Cart and order
| Hook | Type | Purpose |
|---|---|---|
vst_cart_item_data | filter | Add your own data to the cart item. |
vst_order_item_meta | action | Add meta to a new designer order item at checkout. |
vst_order_item_actions | filter | Add your own buttons next to the download buttons in the admin. |
vst_order_item_after | action | Print your own block after the design block of an item in the admin. |
Designer
| Hook | Type | Purpose |
|---|---|---|
vst_designer_allowed | filter | Return false to switch the designer off for a product; WooCommerce then shows its normal price and add-to-cart button. |
vst_designer_config | filter | Adjust the designer configuration. |
vst_enqueue_designer | action | Enqueue your script after the designer's own. |
vst_designer_panels | filter | Add your own panel to the designer. |
vst_designer_toolbar | action | Print buttons in the canvas toolbar. |
vst_feature_enabled, vst_feature_toggles | filter | Turn a customer-facing switch on or off on top of the saved setting, or pass extra switches to the browser. |
vst_available_fonts, vst_allow_external_fonts | filter | Add fonts to the designer; allow an external font stylesheet in the template editor. |
vst_start_presets, vst_scenes, vst_shape_library, vst_material_library, vst_install_kit_products | filter | Extend the start presets, the scenes, the shape library, the material presets and the install kit. |
JavaScript: window.VSTDesigner
The object exists as soon as the designer script has run, so load your script with vst-frontend-js as a dependency (and vst-pricing for the price filter).
| Member | What it does |
|---|---|
on(event, fn) / off(event, fn) | Subscribe or unsubscribe. Events: ready, change, beforeAddToCart, export. |
getDesign() / applyDesign(doc) | Read the current design document or load one. |
refresh() | Re-render and recalculate the price, for example after your own panel changed. |
getCutSVG() | A promise with the cut file as the order would receive it. |
A beforeAddToCart handler may return a promise; if it rejects, the item is not added and the reason is shown to the customer. All handlers together get 10 seconds.
VSTDesigner.on('beforeAddToCart', function (doc) {
if (!document.querySelector('[name="myaddon_date"]').value) {
return Promise.reject(new Error('Please choose a mounting date.'));
}
});
REST and PHP API
The plugin has a REST namespace vst/v1; the vst_rest_init action lets you add routes (give each its own permission_callback). A short list of PHP functions is public API for add-ons, among them vst_get_settings(), vst_feature_enabled(), vst_is_enabled(), vst_designer_active(), vst_get_product_sticker_types() and vst_get_available_fonts(). Anything else is internal.
Pro uses the same API
Pro is itself an add-on built on this public API: it reads the free plugin's order items and design files and adds its own screens and e-mails.