In this tutorial, we demonstrate how to create the Digital Sale Banner site plugin for the Wix Stores product page. This plugin displays a small banner on digital products to let customers know this product is included in the current digital sale promotion. It is meant to be embedded in a Wix Stores product page slot.
The end result will look something like this:
We'll use the following steps to build the Digital Sale Banner 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.
You can access Wix Blocks through the Wix Studio workspace.
Now design your plugin in Wix Blocks:
Open the Widgets and Design panel, click , and select Add Plugin.
In the Add a plugin panel, set up the plugin as follows:
Plugin name: Digital Sale Banner Plugin
Which Wix app does it extend?: Wix Stores
Slots this plugin can be added to: product-page-details-2 (New Product Page)
and product-page-details-2 (Old Product Page)
Note: Check Wix Stores: Product Page to see the available slots.
This example uses the slots for both the new version of Wix Stores product page and the old version. This ensures a user can add your app to their site with whichever version they have.
Click Create.
Add an image element to the plugin.
Click Add Elements on the left side of the editor, and then click Image.
Upload the image that you want to appear on the relevant product pages.
Click Change Image. Select the image you want to use and click Update.
If you find your image is cut off, then reset the image.
Select the image and click on . Click .
Next, let's make sure that when the plugin is added to a site, the image stretches across the entire width of the Wix Product page slot.
Select the image element. In the Inspector panel on the right, click the Layout tab, and set the element's width to 100%.
We now write the code for our plugin. The code checks if the product is digital and, if so, updates the slot on the page to display the digital sale image.
Before coding our plugin, we need to connect our plugin to the host widget (in our case, the Wix Stores product page) by implementing the Product plugin API
.
To do so, add the productId
property to your plugin's public API.
In the code panel, click the Widget Public API icon, and then click Add New Property.
In the New Property panel, name the property productId
, and then click Create.
In the code editor, add the following import statement at the beginning of your code to use Wix Stores APIs:
import { products } from 'wix-stores.v2';
Make the $widget.onPropsChanged()
function asynchronous by adding the async
keyword:
$widget.onPropsChanged(async (oldProps, newProps) => {
Inside the $widget.onPropsChanged()
code block, add the following line to get the current product ID from the host widget:
const currentProductId = newProps.productId;
This ID identifies the product for which the type will be checked.
Use the Wix Stores getProduct()
function to query the type of product:
Check if the product type is digital and, if so, display the digital sale banner:
Here's the complete code:
In the top-right corner, click Build. When prompted to provide an app name, enter "Digital Sale Banner" and then click Save & Continue.
When prompted to select the type of version to build, select Test version.
Your plugin is now ready for use. In the next step, you'll add your plugin to a site to see it in action.
Plugins that you develop are immediately available for installation on your own sites, using the Plugin Explorer in the editors.
Go ahead and create a new site, and then install Wix Stores. Alternatively, use a site template which already has Wix Stores installed.
Open your editor. In the left sidebar, click Pages , then Store Pages, and go to the Product Page.
On the Product page, click the page's widget, and then click the plugins icon.
Your plugin should appear in the Plugin Explorer.
Hover over your plugin, and then click Add.
When prompted for consent, select the checkbox and click Agree & Add.
Once you install your plugin on a site, you can preview or publish the site to test the plugin's functionality and make sure it's working properly.