How can I add a cost to adding custom text?

I’m currently in the process of setting up an online shop that sells sports jerseys, and I’ve added a box for custom text so that my clients can tell me the name and number they want on the jersey. The problem is, I can’t find a way to make it cost extra, and I can’t offer such a service for free.

Optimally, I’d want to have the cost immediately added to the total price as soon as my client types anything on the text box. Is there any way I can add this function to my website?

Edit: I’ve still not managed to solve my problem, I’ve tried to implement Velo/JavaScript code but I cannot find a way to modify the custom text option and add onto the product price as my client types. This is urgent! Please help!

Bump!

I’m new to Wix and Velo, but I have found 2 ways that one can accomplish this; one easy, one a bit more involved.

The ‘easy’ way is to use the wix-stores-backend function of updateProductFields ()

This is fairly simple to do but it has the drawback of changing the price to every reference to that product. So it will also alter the price of ALL items with that product._id in the cart and on the site. If your customer buys 2 of the same items at different prices, the updated price will be for both of those items. Additionally, if you have another customer on the site at that same moment, their price will also be equal to whatever the product price has been change to.

The more convoluted way is to use your store/products database to fill the item information on a custom product page. You then use the createProduct () function to create a new product in an async function. This allows you to set the price dynamically and is what I used for my custom-printed garments in my (soon to be up and running) shop.

This has the drawback of creating lots of items in your stores/products database that will then need to be dealt with. I solved that issue by using the cart events in the events back-end to clear out custom-created products once the cart has been abandoned or paid.

There is also the addCustomItemsToCart( ) function in wix-stores. But to be honest I only noted that it exists recently and I haven’t played with it to see if it would work for this sort of instance, so I cannot say whether or not it will work for you.

Hope that helps.