Urgent!!!!!! Conditionally create a button for specific product

Hi there,
I am not a coder, and just starting to learn some function on Corvid Wix. Can anyone help me out with the explanation below? Much appreciated!

The idea is, on the product page I want to create 2 different buttons for some specific products. There are 3 product collections (let call “a”, “b”, “c”) that I want to put #button1 on. And when product is out-of-stock, I want to put #button2 on. I set default that a, b, c collections are all out of stock but #button2 won’t appear on these collections.

Explanation
On the product page.
- If the product is out of stock and product is in one of 3 collections then
→ button 2 disabled
→ button 1 enabled

- If the product is out of stock and product is not in one of mentioned 3 collections then
→ button 1 disabled
→ button 2 enabled

- If the product is in stock
→ both button disabled.

Sample code:
import wixWindow from ‘wix-window’ ;
import wixData from ‘wix-data’ ;
import wixStores from ‘wix-stores’
$w.onReady( function () {
initPage();
});

async function initPage() {
try {
const product = await $w( ‘#productPage1’ ).getProduct();
if (!product.instock
&& product.collections
.hasSome( ‘a’ , ‘b’ , ‘c’ )
.find()
.then((results) => {
$w( ‘#button2’ ).hide();
$w( ‘#button1’ ).show();
$w( “#button1” ).onClick((event) => {
wixWindow.openLightbox( ‘lightbox’ );
})})
)
if (!product.instock){
$w( '#button1 ).hide();
$w( ‘#button2’ ).show();
$w( “#button2” ).onClick((event) => {
wixWindow.openLightbox( ‘lightbox2’ , { ‘productId’ : product._id });
});
}
}
catch (error) {
console.error( 'product page → initPage error ’ , error);
return false ;
}
}

Please help!!!

Please realize that you can’t just “copy and paste” code and expect it to work. You need to understand what’s happening if you expect to be able to write code that does what you want.

If you find coding a bit too much, it is possible to find expert developers on the Wix Marketplace an online marketplace with top Corvid web developers from around the world.