2016-06-10 65 views
2

我已將以下代碼添加到我的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); 
} 

有什麼不對?

回答

3

您在返回你的函數的值,相反,也許,你需要這樣返回$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; 
} 
+0

這就是工作,感謝您的時間:)。 –

+0

有這個解決方案嗎? http://stackoverflow.com/questions/37760588/how-to-check-which-coupon-is-applied-to-which-product-in-woocommerce –