2

I've addded the below code to my function.php, but it didn't round the price after applying a coupon.

I'm using woocommerce 2.5.5.

This is my code:

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 );
}

What is wrong?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Mûhámmàd Yäsår K
  • 1,492
  • 11
  • 24

1 Answers1

3

You are returning a value in your function, instead, maybe, you need to return the $price variable this way:

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;
}
Mûhámmàd Yäsår K
  • 1,492
  • 11
  • 24
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399