Example Description
In this example we allow site visitors to enter a custom price for a product. Then we create the product and add the product to the cart. This example is useful for processing donations.
How We Built It
Page Elements
On the Home page we added the following elements:
-
Two text inputs for the customer’s name and the custom price
-
An ‘Add to Cart’ button
Code
In the backend customProduct.jsw module, we do the following:
-
Import the Wix Stores Backend module.
-
Add a function for creating a product.
-
Add a function for adding media to a product.
On the Home page, we do the following:
-
Import the backend functions.
-
When the Add to Cart button is clicked, create a new custom product as follows:
-
Set the product name based on the name entered by the customer in the text input.
-
Set the product price based on the price entered by the customer in the text input.
-
Set the product type as physical.
-
Create the product using the backend function.
-
Add media to the product using the product ID returned from the createProduct() function and an image of our choice.
-
Add the product to the cart.
Related Examples
Did this help?
|
Thanks for your feedback!
Collect Payments for a Single Product
Collect quick and secure payments from your site visitors.
Intermediate
Product Configurator
Let customers create one-of-a-kind products.
Advanced
Upsell Products
Promote products based on items in your cart
Intermediate