gpt4 book ai didi

php - 获取woocommerce购物车总量

转载 作者:IT王子 更新时间:2023-10-28 23:54:49 31 4
gpt4 key购买 nike

我正在尝试对购物车总价应用折扣,但我只能对商品基价应用折扣,而不能对总价应用折扣。我用谷歌搜索并找到了this张贴在WordPress 计算器:

$amount = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) ); The preg_replace eliminates everything but decimal characters and colons.

Should you care to do math with it, the floatval converts the value from a string to a numeric one.

我尝试添加:

$amount2 = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) );

和改变

$discount = round( (($discounting_amount / 100 ) *  $this->amount)*-1, WC()->cart->dp);

$discount = round( (($discounting_amount / 100 ) *  $amount2)*-1, WC()->cart->dp);

但是我得到以下错误:

Fatal error: Call to a member function get_cart_total() on a non-object in...

最佳答案

试试这个:

WC()->cart->cart_contents_total

函数 get_cart_total 使用 wc_price 函数将 cart_contents_total 转换为货币。

关于php - 获取woocommerce购物车总量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22249615/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com