简体   繁体   中英

Get total cart woocommerce

I need to have the import of cart in woocommerce . But i need the number without wc_price(). This is my code:

global $woocommerce;
$app=$woocommerce->cart->get_cart_total();
$app2=$woocommerce->cart->total;

and it results:

app = $20.00
app2 = 0

and the cart is of $20.00 Thanks.

You try

$app= (float) preg_replace( '/[^0-9\.]/', '', $woocommerce->cart->get_cart_total()  );

Or

$app = str_replace('$','',$woocommerce->cart->get_cart_total() );

the solution depends on the type of currency that is occupied in this case the euro occupied, so we had to replace the euro in htmlentities as shown here

str_replace ( '& euro;', '', $ woocommerce-> cart-> get_cart_total ());

Note: trim '& euro'

You can try

global $woocommerce;
$Cart = WC()->cart->subtotal;
echo "CART : " . $Cart;

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