Passer la navigation

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

This support ticket is created Il y a 3 years, 4 months. 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 -

Fuseau horaire du supporter : Asia/Kolkata (GMT+05:30)

Ce sujet contient 12 réponses, a 2 voix.

Dernière mise à jour par markP-19 Il y a 3 years, 4 months.

Assisté par: Minesh.

Auteur
Publications
#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

Les langues: Anglais (English )

Fuseau horaire: 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

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Could you please check now: lien caché?

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

Les langues: Anglais (English )

Fuseau horaire: 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

Les langues: Anglais (English )

Fuseau horaire: 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: lien caché

#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

Les langues: Anglais (English )

Fuseau horaire: 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

Les langues: Anglais (English )

Fuseau horaire: 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!