Skip Navigation

[Resolved] Split: Calculate search input field with custom fields – use comma for decimal instead of dot

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 12 replies, has 2 voices.

Last updated by markP-19 2 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2531913

Thanks! it works.

Last thing, how can i make it possible to use comma instead of dot, when typing a value with decimals?
For example the height will be entered as 2 * 3,2 (with comma instead of dot)

#2531917

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean that user will add value with comma and comma should be considered as desimal for both fields "Højde m2" and "Bredde m2"? will both field accept comma or any one of those?

Can you please tell me where you added the shortcode [wpv-calculate]?

#2531931

Sometimes the user needs to calculate for example: 1.2 * 1.4 = 1.68
Instead of typing the dot, is it possible that the user is able to type the values like this: 1,2 * 1,4 = 1,68

#2532001

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now: hidden link?

I've moved the [wpv-calculate] shortcode form your theme's function.php file to "Custom Code" section offered by Toolset and I've adjusted the code as given under:

// Calculate shortcode
add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts) {
  if((isset($_REQUEST['wpv-wpcf-folieprint-hojde']) and $_REQUEST['wpv-wpcf-folieprint-hojde']!='')
      and
     (isset($_REQUEST['wpv-wpcf-folieprint-bredde']) and $_REQUEST['wpv-wpcf-folieprint-bredde']!='')
     ) {
        $hojde_val = str_replace(",",".",$_REQUEST['wpv-wpcf-folieprint-hojde']);
         $bredde_val = str_replace(",",".",$_REQUEST['wpv-wpcf-folieprint-bredde']);
         $result = $hojde_val * $bredde_val;
         return str_replace(".",",",$result);
         
  }
return 0;
}

Can you please check now if it works as expected.

#2532023

Now the calculation results are 0 ?

It calculated fine before when using either values without decimal or for example 1.2 instead of 1,2

#2532025

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That should be from cache. Can you hard refresh the page and check again.

#2532029

I tried and it doesn't work. Also this is displaying front end when testing:

xxx==2yyy===2xxx==2yyy===2xxx==2yyy===2xxx==2yyy===2xxx==2yyy===2xxx==2yyy===2xxx==2yyy===2xxx==2yyy===2

#2532031

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Those values were displaying as I was testing.

You have to select the option "Full page refresh when clicking Submit" from "Custom Search" settings of your view as such custom thing is not working when you are using ajax view.

Can you please check now: hidden link

#2532033

I checked again and also in private in another browser and with full page refresh, it doesn't work

If i for example enter 1 in height and 1,3 in width (bredde), the calculation is 1,3. It seems like it is missing the multiply with 'pris-folieprint'

The full calculation must include the 'pris-folieprint' as following:

[wpv-calculate evaluate=" [wpv-search-term param='wpv-wpcf-folieprint-hojde'] * [wpv-search-term param='wpv-wpcf-folieprint-bredde'] * [types field='pris-folieprint' format='FIELD_VALUE'] [/types] "]

#2532037

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I was having impression that you just want to multiply values of "Højde m2" and "Bredde m2" but you have "pris-folieprint" field is also involved.

So, I've adjusted the code as given under:

add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts) {
  if((isset($_REQUEST['wpv-wpcf-folieprint-hojde']) and $_REQUEST['wpv-wpcf-folieprint-hojde']!='')
      and
     (isset($_REQUEST['wpv-wpcf-folieprint-bredde']) and $_REQUEST['wpv-wpcf-folieprint-bredde']!='')
     ) {
        global $post;
        $hojde_val = str_replace(",",".",$_REQUEST['wpv-wpcf-folieprint-hojde']);
         $bredde_val = str_replace(",",".",$_REQUEST['wpv-wpcf-folieprint-bredde']);
         $pris = get_post_meta($post->ID,'wpcf-pris-folieprint',true);
         $result = $hojde_val * $bredde_val * $pris;
         
         return str_replace(".",",",$result);
         
  }
return 0;
}

This should be fixed now.

#2532041

It works, thanks !

#2532043

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that solution I shared help you to resolve your issue. You can mark resolve this ticket.

#2532045

My issue is resolved now. Thank you!