Add a product to the cart when a button is clicked

How do I get this code to work when I click a button on my product page?
I need to add a product to the cart so that the person can go to a measurement page, fill in their measurements and return to the product page to purchase the item.
Thanks Keith Green
$w(“#myButton”).onClick( () => {
$w(“#myShoppingCartIcon”).addToCart(“ea77f230-558f-0ba565e8f827”)
.then( () => {
console.log(“Product added”);
} )
.catch( (error) => {
console.log(error);
} );
} );