skip to Main Content

I need help to correct the PHP function. For explanation: I have a price 1.45 and I need to add 10% to this price, but with no roundings. It should show up in woocommerce: 1,595
Hope I explain right 🙂

<?php
function calc_price_net ( $price = null ) {
    
        $price = round ( ( $price *  1.1 ), 0 );
        
    return $price;

}
?>

Instead of round what should be?

thanks a lot for help.
Lucy

2

Answers


  1. Chosen as BEST ANSWER

    thank you very much for answers. But I am totally beginner. If you can please write to whole code. Because non of these worked. But maybe because I did not write them correctly. Please help.


  2. function addPercentage($price, $percentage) {
        // Ensure the inputs are numbers
        if (!is_numeric($price) || !is_numeric($percentage)) {
            return "Invalid input: Please provide numeric values for both price and percentage.";
        }
    
        // Calculate the new price with the given percentage added
        $newPrice = $price * (1 + ($percentage / 100));
    
        return $newPrice;
    }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search