Ich möchte den Gesamtpreis des Warenkorbs in meinem Woocommerce-Plugin erhalten.woocommerce - Get Cart Total als Nummer
Ich möchte es als Float-Nummer wie folgt erhalten: 21.00, aber ich weiß nicht, wie man es bekommt. Mein Code gibt seltsame Ergebnisse, das ist mein genauer Code:
$total = $woocommerce->cart->get_total();
$total_a = WC()->cart->get_total();
$total1 = $woocommerce->cart->get_total_ex_tax();
$total1_a = WC()->cart->get_total_ex_tax();
$total2 = $woocommerce->cart->get_cart_total();
$total2_a = WC()->cart->get_cart_total();
Ausgänge:
0,00 €
0,00 €
0,00 €
0,00 €
21,00 €
21,00 €
und wenn ich aus Zeichenfolge konvertiere das Ergebnis zu schwimmen ist natürlich 0,00.
Irgendwelche Hilfe, wie man Karrensumme in Form der Flosszahl erhält?
Schauen Sie in die Wagenklasse. ['get_total()'] (https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-cart.php#L1959) Methode formatiert den Preis mit 'wc_price()'. Also, wie @ José darauf hingewiesen hat, müssen Sie nur auf das öffentliche Eigentum zugreifen. – helgatheviking
gruß gelöscht – gsamaras