我正在尝试对购物车总价应用折扣,但我只能对商品基价而不是总价进行折扣。我用谷歌搜索并在 wordpress stackoverflow 中看到了这篇文章:
$amount = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) ); preg_replace 消除了除十进制字符和冒号之外的所有内容。
如果您愿意用它来做数学运算,floatval 会将值从字符串转换为数字。
我尝试添加:
$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...