Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:16:48+00:00 2026-06-11T22:16:48+00:00

I have a big time trying to either convert a string into a integer

  • 0

I have a big time trying to either convert a string into a integer or multiply two integers. I can’t convert the string into integer because it’s resulting me into a boolean (when I’m using var_dump). I can convert the other integer in string, but I’m unable to multiply it.

I have this:

    <? $fees=$commerce->cart->get_total(); 
    $payfee = str_replace('&nbsp;&euro;', '', $fees);
    $payfee = str_replace(',','', $payfee);  //this is the string
    $fee = 0.025;
    $paypal = $payfee * $fee;  //this thing is not working

    ?>

I tried converting the payfee in integer, but still can’t make it work. I did something like this before and worked well, but not this time.

Any help will be appreciated.

P.S Thank you to the whole stackoverflow.com community which helped me many times before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:16:50+00:00Added an answer on June 11, 2026 at 10:16 pm

    OP is running WooCommerce, and his $commerce->cart->get_total();
    function responds output such as <span class="amount">560&nbsp;&euro;</span> (560 €)
    and he’s asking how to convert this to a number so he can get a fee
    (2.5 %) from the amount.

    First of all, the problem here is that the get_total() function responds with a string.

    The correct way to fix this string would be a simple example such as

    <?php
        $totalAmountString = $commerce->cart->get_total(); //<span class="amount">560&nbsp;&euro;</span>
        $totalAmountString = strip_tags($totalAmountString); //get rid of the span - we're left with "560&nbsp;&euro;"
        $totalAmountString = str_replace(array("&nbsp;&euro;", ","), "", $totalAmountString);
        $totalAmountFloat = (float)$totalAmountString;
        $fee = 0.025;
        $feeForThisAmount = $totalAmountFloat * $fee;
        var_dump($feeForThisAmount);
    
        $totalAmountWithFee = $totalAmountFloat + $feeForThisAmount;
        var_dump($totalAmountWithFee);
    ?>
    

    However, according to the Woo Commerce API Documentation you should be able to use $commerce->cart->total to get a float of the number, so a solution that might also work (again, I know nothing about WooCommerce), would be the following:

    <?php
        $totalAmountFloat = $commerce->cart->total;
        $fee = 0.025;
        $feeForThisAmount = $totalAmountFloat * $fee;
        var_dump($feeForThisAmount);
    
        $totalAmountWithFee = $totalAmountFloat + $feeForThisAmount;
        var_dump($totalAmountWithFee);
    ?>
    

    Edit

    According to your latest data dump, the problem is that you’re using

    $paypal_fees=$woocommerce->cart->get_total() * 0.025;
    

    where you should be using

    $paypal_fees=$woocommerce->cart->total * 0.025;
    

    as ->get_total() receives a string, and ->total receives a float.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to dive into Qt big time but haven't done a large project with
I have a big problem using highcharts, because I have been trying for hours
I have some big .csv files and I am trying to put it into
I have big problem. Every time when I'm trying to connect to any jabber
I have a big question that has been puzzling me for a long time
I have a very big constant array that is initialized at compile time. typedef
I'm studying the running time of programs and have come across the Big O
I have big problem when I am trying to deploy my app over clickonce.
I have a big file full of integers that I'm loading in. I've just
Trying to load a file into python. It's a very big file (1.5Gb), but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.