Dynamic variant selection

nitai
New Member
1 0 0

Hello,

I am trying to create a page where my customer can order a custom mat. For that, I have added input fields for the custom width and the custom depth. Depending on those measurements, I need to select and a specific variant of my product. I am not a programmer. I did a very simple code in JavaScript that works when I test it in the console.log but I don't know how to make it work in Shopify.  Any help would be greatly appreciated. 

Many thanks!

Luis.

 

var widthResult = width;
var depthResult = depth;
var customMessage = "Please contact our customer service team to order. Call 5555555. Email orders@abc.com";

function customMatResult(widthResult, depthResult) {

var customMatSelection;

if (widthResult <= 20 && depthResult <= 14) {
return "CUSTOM MAT2014";
}  

else if (widthResult <= 24 && depthResult <= 14) {
return "MCUSTOM MAT2414";

else if (widthResult <= 32 && depthResult <= 14) {
return "CUSTOM MAT3214";

else if (widthResult <= 25 && depthResult <= 18) {
return "CUSTOM MAT2518";

else if (widthResult <= 30 && depthResult <= 30) {
return "CUSTOM MAT3030";

else if (widthResult <= 36 && depthResult <= 30) {
return "CUSTOM MAT3630";

else if (widthResult <= 36 && depthResult <= 36) {
return "CUSTOM MAT3636";

else if (widthResult <= 48 && depthResult <= 36) {
return "CUSTOM MAT4836";  

else if (widthResult <= 60 && depthResult <= 40) {
return "CUSTOM MAT6040";

else if (widthResult <= 70 && depthResult <= 50) {
return "CUSTOM MAT7050";

else { 
return customMessage;
}

return customMatSelection;

}
0 Likes