Service plugin extensions are a set of APIs defined by Wix that you can use to enable your headless project to inject custom logic into the backend flows of Wix business solutions or to introduce entirely new flows.
You can implement service plugin extensions in your project using the CLI for Headless.
Follow the instructions below to:
Once this task is complete, your project will have a service plugin extension with custom functions that Wix calls during a specific flow in your project.
In the terminal:
Navigate to your project repo.
Run the following command:
The CLI will display a menu of extensions to generate. Select Service Plugin and hit enter to continue.
The CLI will prompt you to select a service plugin from a list of available service plugins.
The CLI will prompt you to name your service plugin. This is the name of the folder in the project repo that contains the service plugin code, and the name of the plugin that appears in your project. Only you will see this name.
Upon completion, the extension files will be created in your project directory with the following structure:
extension.json
- This file is required and provides all required configuration for your plugin.plugin.ts
- This file is required and contains handler functions that Wix calls automatically when the relevant action in your project triggers them. These functions are where you add your custom logic.To test your service plugin extension you must:
New service plugins or changes to existing service plugins won't take affect until you've built and released your project.
Important:
Logging in the backend logic of service plugins can't be tested in the CLI's local development environment (npm run dev
). Instead, you must trigger the call to the service plugin from your development site and check for the expected result.
For example, to test a service plugin extension for Additional Fees that adds a $5 packaging fee to all orders:
Run the following command to build your project:
Run the following command and follow the prompts to release your project:
For more information about building and deploying your project, see Build and Deploy a Project with the Wix CLI for Headless.
To delete a service plugin extension from your project, delete the subfolder under src/extensions
that contains your service plugin extension's files.