Q: How to make a ‘Buy Now’ button for 1 digital product instead of the “Add to Cart” btn?
Goal: On a custom page, I want customers to click “Buy Now” & directly go to checkout without going through the cart. For an instant purchase without extra steps.
Attempts: -The only available native buttons linked to Wix Stores are inside widgets, which can’t be accessed straightforwardly. Only add to cart buttons are available. I haven’t found a ‘Buy Now’ button
This seems like a good approach for me. How do I implement this in Wix Editor? Is there a nocode/native solution? I tried different approaches using velo too, none has worked yet. I get different versions of failed checkout pages. Maybe the new Wix stores/wix ecom doesn’t the foll code? Or sdk is better? Hope it can be done with simple page code before trying with backend Approach 1)
import wixLocation from 'wix-location';
$w.onReady(() => {
const STORE_URL = "https://www.openrescue.com"; //I also tried the product pg
const PRODUCT_ID = "1782649327875000"; //also tried inventory id
$w("#buyNowButton").onClick(() => {
const checkoutUrl =
`${STORE_URL}/checkout?items=${PRODUCT_ID}:1`;
wixLocation.to(checkoutUrl);
});
});
There isn’t really a clean no-code/native solution for placing a custom “Buy Now” button anywhere on a custom page. The native Buy Now button is available on the Wix Product Page, but a standalone custom button needs Velo.
The issue with your first approach is that Wix checkout does not reliably work from a manually built URL like /checkout?items=PRODUCT_ID:1. Checkout needs to be created from an actual cart/checkout session.
Also, your second approach uses the older wix-stores-frontend cart API, which is now deprecated. I’d use the newer Wix eCom/currentCart flow instead: add the product to the visitor’s current cart, create a checkout from that cart, then navigate to that checkout.
something like this should work. Just make sure PRODUCT_ID is the actual Wix Stores product ID, not the inventory ID.
Hey Dan, hope you’re well. Many thanks for that detailed response.
The issues with the 2 approaches you pointed out were exactly in line gpt’s earlier diagnoses.
I tried your code & got 2 red underlines in it
Under ‘channelType’: Type ‘“WEB”’ is not assignable to type ‘ChannelType$3’.
Under ‘checkoutId’: Argument of type ‘CreateCheckoutResponse’ is not assignable to parameter of type ‘string’.
After a lot of back & forth with gpt from then, I got no where. Here are some further attempts;
As it instructed, above errors were cleared with the following changes;
1.
import { currentCart, ChannelType } from 'wix-ecom-backend';
(but that created a red underline under the import line’s ChannelType
2)
It also said there may be an issue with the product id format? That it may need some GUID like this?1a2d7e83-4bef-31d5-09e1-3326ee271c09
The ID I always used was the numericId . It’s right, right?
A broader Q I’ve had for a while: I’ve used this GPT (ChatGPT - W Epic Solutions) so far to aid me code. But I think it’s limited to Velo & older infrastructure.. How can update this/modify a gpt/other llm to respond more accurately from updated API refs & SDK?
I’m not a dev, am a rookie coder building & coding myself & learn with tutorials & ai as much as I can before asking for people’s help. So I don’t wanna be take your time unless I’ve tried a lot/made sufficient findings to add value here.