如何在WooCommerce中申请优惠券后的价格?

时间:2016-06-10 12:04:58

标签: php wordpress woocommerce product price

我已将下面的代码添加到我的 function.php 中,但在应用优惠券后它没有计算价格。

我正在使用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 );
}

有什么问题?

1 个答案:

答案 0 :(得分: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;
}