• Resolved mlarge

    (@mlarge)


    I set up 8 product pages through WooCommerce. Then I set up a calculator with two number fields that the user will enter. The user will hit next to be presented with their specific custom product (1 of 8) depending on what the user enters. OR I need the next button to show the price of that particular product to then BUY it. Is this possible? Or is there another solution to show 1 of 8 prices based off the two number fields? I tried the hide/show function but it’s not working. Is there a way to have the BUY button take them to a specific URL (Product Page) based off the input of the two number fields? Please help!!!

    https://www.ads-software.com/plugins/calculated-fields-form/

Viewing 13 replies - 31 through 43 (of 43 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    You’ve not followed the steps in the article on my technical blog in the correct way, the definition of the “setFieldValue” routine, and its execution, should be included in <script></script> tags. If you are needing additional support on this subject, you should hire a custom coding service.

    Best regards.

    Thread Starter mlarge

    (@mlarge)

    I followed the instructions on the link below exactly as it states and the result fields display like the above. “setFieldValue(‘fieldname3_1′, ‘2‘ );”
    It doesn’t say anything about adding <script> tags and how to get the results in a field.

    https://blog.net-factor.com/how-to-use-the-data-submitted-by-a-form-in-another-one/

    Thread Starter mlarge

    (@mlarge)

    I added the script tag and no results are shown. Is it supposed to show in a field? That is the confusing part of your instructions. I have this code in the product page.

    [CP_CALCULATED_FIELDS_RESULT]
    <script>
    setFieldValue(‘fieldname2_1’, ‘<%fieldname2_value%>’ );
    setFieldValue(‘fieldname3_1’, ‘<%fieldname3_value%>’ );
    </script>
    [/CP_CALCULATED_FIELDS_RESULT]

    [CP_CALCULATED_FIELDS id=”21″]

    <script>
    function setFieldValue(field, value) {
    $(‘[id=”‘ + field + ‘”]’).each(
    function () {
    var e = $(this),
    attr = e.attr(‘vt’),
    t = this.tagName;
    if (typeof attr == ‘undefined’ && t != ‘SELECT’) {
    e.val(value);
    if (e.hasClass(‘phone’)) {
    value = $.trim(value)
    .replace(/[^\d]/g, ‘ ‘)
    .split(‘ ‘);
    for (var j = 0, h = value.length; j < h; j++) {
    $(‘[id=”‘ + field + ‘_’ + j + ‘”]’).val(value[j]);
    }
    } else if (e.hasClass(‘date’)) {
    value = $.trim(value).split(‘ ‘);
    $(‘[id=”‘ + field + ‘_date”]’).val(value[0]);
    if (value.length > 1) {
    var time = value[1].split(‘:’);
    $(‘[id=”‘ + field + ‘_hours”]’).val(time[0]);
    $(‘[id=”‘ + field + ‘_minutes”]’).val(time[1]);
    }
    }
    } else {
    if (t == ‘SELECT’) {
    e.find(‘[vt=”‘ + value + ‘”]’)
    .prop(‘selected’, true);
    } else {
    if ((typeof value == ‘object’ &&
    $.inArray(attr, value) != ‘-1’) ||
    attr == value) {
    e.prop(‘checked’, true);
    }
    }
    }
    }).change();
    };
    </script>

    Plugin Author codepeople

    (@codepeople)

    Hi,

    The issue is simple, you have copied and pasted the javascript code with the “Visual” tab active in your webpage’s editor, or has been copied the code as HTML, look the symbols in the page’s content, they have been encoded as HTML

    Visit the following link to see the screenshot:

    https://wordpress.dwbooster.com/customdownloads/2015-09-16/screenshot.png

    My recommendation is to paste all javascript code inside the tags:

    [CP_CALCULATED_FIELDS_RESULT]
    <pre style="display:none;">
    <script>
    ...
    </script>
    </pre>
    [/CP_CALCULATED_FIELDS_RESULT]

    Replaces the symbols … by all the javascript code, included the routine’s definition.

    Best regards.

    Thread Starter mlarge

    (@mlarge)

    I did exactly as above and there are no results on this page. Are the results supposed to be in a field?

    Plugin Author codepeople

    (@codepeople)

    Hi,

    I’ve checked your website again and the code has not been inserted as should be. Please, replace your current code with this one:

    [CP_CALCULATED_FIELDS_RESULT]
    <pre style="display:none;"><script>
    function setFieldValue(field, value) {
      $('[id="' + field + '"]').each(
        function () {
        var e = $(this),
        attr = e.attr('vt'),
        t = this.tagName;
    
        if (typeof attr == 'undefined' && t != 'SELECT') {
          e.val(value);
          if (e.hasClass('phone')) {
            value = $.trim(value)
                     .replace(/[^\d]/g, ' ')
                     .split(' ');
            for (var j = 0, h = value.length; j < h; j++) {
               $('[id="' + field + '_' + j + '"]').val(value[j]);
             }
           } else if (e.hasClass('date')) {
             value = $.trim(value).split(' ');
             $('[id="' + field + '_date"]').val(value[0]);
             if (value.length > 1) {
              var time = value[1].split(':');
              $('[id="' + field + '_hours"]').val(time[0]);
              $('[id="' + field + '_minutes"]').val(time[1]);
            }
          }
        } else {
          if (t == 'SELECT') {
            e.find('[vt="' + value + '"]')
             .prop('selected', true);
          } else {
            if ((typeof value == 'object' &&
                 $.inArray(attr, value) != '-1') ||
                 attr == value) {
              e.prop('checked', true);
            }
          }
        }
      }).change();
    };
    jQuery(function(){
    setTimeout(function(){
    setFieldValue('fieldname2_1', '<%fieldname2_value%>' );
    setFieldValue('fieldname3_1', '<%fieldname3_value%>' );
    }, 2000);
    });
    </script></pre>
    [/CP_CALCULATED_FIELDS_RESULT]

    I’m sorry but the support service does not include the implementation of users projects. If you need additional support in this point you should hire a custom coding service.

    Best regards.

    Thread Starter mlarge

    (@mlarge)

    Still doesn’t do anything but thanks for your help.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Could you try again, but this time with this code, please:

    [CP_CALCULATED_FIELDS_RESULT]
    <pre style="display:none;"><script>
    function setFieldValue(field, value) {
      jQuery('[id="' + field + '"]').each(
        function () {
        var e = jQuery(this),
        attr = e.attr('vt'),
        t = this.tagName;
    
        if (typeof attr == 'undefined' && t != 'SELECT') {
          e.val(value);
          if (e.hasClass('phone')) {
            value = jQuery.trim(value)
                     .replace(/[^\d]/g, ' ')
                     .split(' ');
            for (var j = 0, h = value.length; j < h; j++) {
               jQuery('[id="' + field + '_' + j + '"]').val(value[j]);
             }
           } else if (e.hasClass('date')) {
             value = jQuery.trim(value).split(' ');
             jQuery('[id="' + field + '_date"]').val(value[0]);
             if (value.length > 1) {
              var time = value[1].split(':');
              jQuery('[id="' + field + '_hours"]').val(time[0]);
              jQuery('[id="' + field + '_minutes"]').val(time[1]);
            }
          }
        } else {
          if (t == 'SELECT') {
            e.find('[vt="' + value + '"]')
             .prop('selected', true);
          } else {
            if ((typeof value == 'object' &&
                 jQuery.inArray(attr, value) != '-1') ||
                 attr == value) {
              e.prop('checked', true);
            }
          }
        }
      }).change();
    };
    jQuery(function(){
    setTimeout(function(){
    setFieldValue('fieldname2_1', '<%fieldname2_value%>' );
    setFieldValue('fieldname3_1', '<%fieldname3_value%>' );
    }, 2000);
    });
    </script></pre>
    [/CP_CALCULATED_FIELDS_RESULT]
    Thread Starter mlarge

    (@mlarge)

    Hello,

    Still no luck. Not sure what the issue is.

    Thanks

    Plugin Author codepeople

    (@codepeople)

    Hi,

    I’m sorry, but this code is not part of the plugin, and would be needed modify it to be adjusted to your webpage.

    Best regards.

    Thread Starter mlarge

    (@mlarge)

    ok, thanks for your help anyway.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    I’ve took a look again to your page and the issue is simple, you are trying to assign the values to the fields:

    setFieldValue('fieldname2_1', '<%fieldname2_value%>' );
    setFieldValue('fieldname3_1', '<%fieldname3_value%>' );

    But the form in the page does not includes the fields fieldname2 or fieldname3, you should use the name of the corresponding fields in the new form:

    setFieldValue('fieldname11_1', '<%fieldname2_value%>' );
    setFieldValue('fieldname12_1', '<%fieldname3_value%>' );

    Best regards.

    Thread Starter mlarge

    (@mlarge)

    That worked!!! Thank you so much for all your help!!! ??

Viewing 13 replies - 31 through 43 (of 43 total)
  • The topic ‘Link to a specific WooCommerce product page based off user input’ is closed to new replies.