function matchesMetafield(product,metafield,userChoice) {
    // Does this product have a match with the user's chosen product type?
    if (userChoice === undefined) { // No type chosen
      return true;
    }
    // This particular product might have no stored data for this user's choice
    else if (!product[metafield]) {
      return false;
    } else {
      var arTypes = product[metafield].split('|');
      // The last item is just filler
      arTypes.length = (arTypes.length - 1);
      // Loop through the array of product types associated with this product, to find a match
      for (var i = 0; i < arTypes.length; i++) {
        if(arTypes[i] === userChoice) return true;
      }
      return false;
    }
  }
// It compares the type to each item in the metafield array then returns a boolean.
It compares the type to each item in the metafield array then returns a boolean.
It compares the type to each item in the metafield array then returns a boolean .
function matchesMetafield(product,metafield,userChoice) {
    if (userChoice === undefined) { 
      return true;
    }
    else if (!product[metafield]) {
      return false;
    } else {
      var arTypes = product[metafield].split('|');
      arTypes.length = (arTypes.length - 1);
      for (var i = 0; i < arTypes.length; i++) {
        if(arTypes[i] === userChoice) return true;
      }
      return false;
    }
  }
function matchesMetafield ( product , metafield , userChoice ) { if ( userChoice === undefined ) { return true ; } else if ( ! product [ metafield ] ) { return false ; } else { var arTypes = product [ metafield ] . split ( '|' ) ; arTypes . length = ( arTypes . length - 1 ) ; for ( var i = 0 ; i < arTypes . length ; i ++ ) { if ( arTypes [ i ] === userChoice ) return true ; } return false ; } }
It compares the type to each item in the metafield array then returns a boolean.
It compares the type to each item in the metafield array then returns a boolean .
// Does this product have a match with the user's chosen product type? // No type chosen // This particular product might have no stored data for this user's choice // The last item is just filler // Loop through the array of product types associated with this product, to find a match