本文介紹了woocommerce - 獲取購物車總數作為數量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想在我的 woocommerce 插件中獲取購物車的總價.
I want to get total price of cart in my woocommerce plugin.
我想將其作為浮點數獲取,如下所示:21.00 但我不知道如何獲取.我的代碼輸出奇怪的結果,這是我的確切代碼:
I want to get it as a float number like so: 21.00 but I don't know how to get it. My code outputs weird results, this is my exact 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();
輸出:
0,00 €
0,00 €
0,00 €
0,00 €
21,00 €
21,00 €
如果我從字符串轉換為浮點數,結果當然是 0.00.
and if I convert from string to float the result is of course 0.00.
任何幫助如何以浮點數的形式獲取購物車總數?
Any help how to get cart total in the form of float number ?
推薦答案
我有這樣的代碼并且工作完美:
I have code like this and working perfect:
if ( ! WC()->cart->prices_include_tax ) {
$amount = WC()->cart->cart_contents_total;
} else {
$amount = WC()->cart->cart_contents_total + WC()->cart->tax_total;
}
祝你好運!
這篇關于woocommerce - 獲取購物車總數作為數量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!