如何在WooCommerce中应用优惠券后整理价格?
问题描述:
我已将以下代码添加到我的function.php中,但它在应用优惠券后并未将价格四舍五入。如何在WooCommerce中应用优惠券后整理价格?
我正在使用woocommerce 2.5.5。
这是我的代码:
add_filter('woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1);
add_filter('woocommerce_get_price_including_tax', 'round_price_product', 10, 1);
add_filter('woocommerce_tax_round', 'round_price_product', 10, 1);
add_filter('woocommerce_get_price', 'round_price_product', 10, 1);
function round_price_product($price){
// Return rounded price
return round($price);
}
有什么不对?
答
您在返回你的函数的值,相反,也许,你需要这样返回$price
变量:
add_filter('woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1);
add_filter('woocommerce_get_price_including_tax', 'round_price_product', 10, 1);
add_filter('woocommerce_tax_round', 'round_price_product', 10, 1);
add_filter('woocommerce_get_price', 'round_price_product', 10, 1);
function round_price_product($price){
//Store and Return rounded price
$price = round($price);
return $price;
}
这就是工作,感谢您的时间:)。 –
有这个解决方案吗? http://*.com/questions/37760588/how-to-check-which-coupon-is-applied-to-which-product-in-woocommerce –