How to round price after applying coupon in WooCommerce?

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.

Read More

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?

Related posts

Leave a Reply

1 comment

  1. 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;
    }