In this tutorial, you'll create a digital sale banner site plugin for the Wix Stores product page using the CLI. This plugin displays a small banner on digital products to let customers know this product is part of the digital sale promotion. The plugin appears in a Wix Stores product page slot.
Follow these steps to build the product page site plugin:
Note: Slots differ slightly depending on which version of Wix Stores a user has on their site. This tutorial works for both versions. Learn more about building product page site plugins.
Create a new app project using the CLI. For detailed instructions, see Quick Start an App.
Add a site plugin extension to your app that renders on a Wix Stores product page.
To add a site plugin extension, follow these steps:
Run the following command:
When prompted, make sure to select the following:
Site Plugin as the extension.Wix Stores as the Wix app.product-page-details-2 as the slot under New product page.Open your plugin's extension.ts file and add support for the old product page slot so your plugin works with both versions of Wix Stores. The old product page uses the same slotId but has different appDefinitionId and widgetId values. Add the following placement to the placements array:
Add code to check if a product is digital and then display a sale banner on digital products. If it's not a digital product, don't display any banner.
Important: You must support both Stores V1 APIs and Stores V3 APIs because different sites may have different API versions available. Your plugin should try both APIs and use whichever one works.
To code your plugin:
Open src/site/plugins/custom-elements/digital-sale-banner/plugin.tsx.
Delete the existing code in the file.
Paste the following import statements at the beginning of your file:
Note: Import both Products V1 API and Products V3 API.
Create the custom element class. Define the class that extends HTMLElement and set up the observed attributes:
Add the method that checks if the product is digital. This method tries both the Products V1 API and Products V3 API and uses whichever one works:
Add the render method that displays the banner on the site:
Export the class as the default export:
When you finish developing your plugin, test it in the development environment. To test your app, use the following steps:
Start the development server:
Select Editor to open an editor in a local development environment.
Navigate to Store Pages > Product Page in the editor. Your plugin should appear in the product-page-details-2 slot.
Build and deploy your app. For detailed instructions, see Build and Deploy a Project.