Show text box based on Product ID's

Hi guys,

I’m new to Velo but I really start to enjoying it.
Currently im having this issue because of a WIX update removing the Cart.AddCustomerItem() functions.

What I want to achieve is the following:
On the standard product page I would like to add a textbox next to the quantity. This textbox should only be shown in case of 2 (in the future maybe more) product ID’s.

This is what I got so far:


$w.onReady(function ShowTextOnProductID() {
    $w('#productPage1').getProduct()
    .then (ShowTextOnProductID);
        
 
    $w('#text91').show ;if (ProductID) IN ('A','B')
    else $w('#text91').hidden
})

Hopefully somebody in the community can give me the right bit of advice.

Thanks in advance
Steve

Hi Steve, it should work with something like this

let currentItem = $w ( ‘#dataset1’ ). getCurrentItem ();

let currentID = parseFloat ( ${ currentItem._id } );
OR let currentID = String ( ${ currentItem._id } );

if ( currentID == productId1 ){
$w ( ‘#text91’ ). text = “your text” ;
$w ( ‘#text91’ ). show ();
} else if ( currentID == productId2 ){
$w ( ‘#text91’ ). text = “your text 2” ;
$w ( ‘#text91’ ). show ();
} else $w ( ‘#text91’ ). hide ();

Things you might need to adjust:

  • the line “let currentID…” with the parseFloat/String or even leave both out.
  • the == of the if statement, which could also need ===
  • for productId insert the corresponding productID

otherwise it should work out when you have a dataset created on your page (here #dataset1)

It doesnt work , also I do not create a dateset created on the page. Maybe need import product first from wix-stores module?

Hi,
I just tried it for on my site.
You may want to add:

$w ( ‘#dataset1’ ). onReady (()=>{ [Previous Code] })

Also set the whole thing into your page onReady function.
https://www.wix.com/velo/reference/wix-dataset/dataset/getcurrentitem

the #dataset1 needs a reference on the page to work out, so you will have to add a dataset to your page.

Thanks for replying! not still working for me…

I see the problem here, you did not adjust the fields from my first message, so ill just copy in the complete code:

$w ( ‘#dataset1’ ). onReady (()=>{
let currentItem = $w ( ‘#dataset1’ ). getCurrentItem ();
let currentID = String ( ${ currentItem._id } );
if ( currentID === productId1 ){
$w ( ‘#text91’ ). text = “your text” ;
$w ( ‘#text91’ ). show ();
} else if ( currentID === productId2 ){
$w ( ‘#text91’ ). text = “your text 2” ;
$w ( ‘#text91’ ). show ();
} else $w ( ‘#text91’ ). hide ();
})

in your first message, you said you only want a certain text when specific products are displayed. You will have to paste the product ID from the Stores/Products collection into productId1 and productId2

thank you very much!

I feel like im almost there. I just see the text still for every product…

$w ( ‘#dataset1’ ). onReady (()=>{
let currentItem = $w ( ‘#dataset1’ ). getCurrentItem ();
let currentID = String (${ currentItem . _id });
if ( currentID === ‘d800b407-c1e0-4e74-b307-80466f9e3799’ ){
$w ( ‘#text91’ ). text = “your text” ;
$w ( ‘#text91’ ). show ();
} else if ( currentID === ‘66bea01c-c54d-400f-a1fc-565e8030bb96’ ){
$w ( ‘#text91’ ). text = “your text 2” ;
$w ( ‘#text91’ ). show ();
} else $w ( ‘#text91’ ). hide ();
})

Or is the ID string not well formed?

Do you see “your text” or “your text 2”?
Can you put “console.log(currentID)” underneath let currentID = String (${ currentItem . _id }); and send a screenshot of what is logged in the console

The Console shows the ID i put in hardcoded. However “your text” or “your text 2” are not showing :frowning:

Mhh okay, very strange. Try to use == instead of ===, maybe that works. If not put a console.log() with continous numbers inside each if statement, so we know if and where its stuck.

Coding is a lot of Trail and Error :sweat_smile:

You could also try to put the product IDs into strings (String(‘d800b407-c1e0-4e74-b307-80466f9e3799’))

Thanks for your time again, really appreciate it. It think the problem is that it doesnt retrieve the right CurrentID. When adding the debuglog node it gives back another ID instead of the one i hardcoded :s

When I remove all other lines from the dataset and leave it with just the two I used hardcoding, it gives back always the same ID. Thats interesting… Do you have any ideas on how to make that current ID retrieve better?

$w ( ‘#dataset1’ ). onReady (()=>{

let currentItem = $w ( ‘#dataset1’ ). getCurrentItem ();
let currentID = String (${ currentItem . _id });
console . log ( currentID )
if ( currentID == ( String ( ‘d66bea01c-c54d-400f-a1fc-565e8030bb96’ )))
{
$w ( ‘#text90’ ). text = “huurdagen1” ;
$w ( ‘#text90’ ). show ();
} else if ( currentID == ( String ( ‘d800b407-c1e0-4e74-b307-80466f9e3799’ )))

{ 
    $w ( '#text90' ). text  =  "huurdagen2" ; 
    $w ( '#text90' ). show (); 
}  **else**  $w ( '#text90' ). hide (); 

})

It always returns d800b407-c1e0-4e74-b307-80466f9e3799, also when it is put in the first if statement.

I would repeat what you said to see if I understood it right.
console.log(currentID) always returns the same ID independent on which product you are looking at but still the text if the if statement which is bound to this ID is not shown.

I unfortunately am not a pro and only can reference to what I learned building my website but what I would do next is at a
console . log ( currentItem )
To see if at least the selected item is the right one. And look if there the id is changing according to each item.

HI Matthias,

No problem I really appreciate your time and effort.

The text is showing for every product.
I already did the lognode with currentItem and still just showing that one ID unfortunately.

Steve

Okay too bad, I am out of my knowledge there but you could try to convert this to a dynamic page and there again add the dataset for Stores/Products

Thanks, also tried it but still returns the same ID. Another product though, but still the same ID over and over again.

Again thanks for your help!

Best to contact the support, this will take a few days but they in my experience come up with an easy solution and send it to

Thank you