简体   繁体   中英

How do I change $cart_total to an actual number?

I am integrating mercadopago (Brasil's version of paypal) into my existing shopping cart that currently checks out and person makes bank deposit.

All seems well except the unit_price is a fixed number.

$preference_data = array(
    "items" => array(
       array(
           "title" => "Shirt",
           "quantity" => 1,
           "currency_id" => "BRL",
           "unit_price" => "10.00"
       )
    )
);

I have tried saying "unit_price" => "$cart_total" but it returned an error saying unit_price must be a number. is there any way around this?

I have miraculously developed my own website and have a .php cart but I am not entirely knowledgeable in this area!!!! Thank you so much! Sorry about the easy question, I couldn't find the answer because I don't know how to properly word it. I tried looking for "converting php string to integer" but that returned results that did not apply...

Just don't use quotes when setting unit_price . As for the quantity number, instead of:

"unit_price" => "10.00"

do:

"unit_price" => 10.00

Read more about PHP types: http://php.net/manual/en/language.types.php

尝试-

"unit_price" => (float)$cart_total,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM