Help adding some basic arithmetic to my existing code

Hi.

Thanks for letting me in :slight_smile:

I need some help adding a bit of simple maths to my existing code. I have a plugin on my WordPress site which updates stock details including price. I can add code to this plugin to perform additional functions but I don’t know enough about PHP to do this.

Currently the code does some calculation based on field values of the import CSV file as below: -

function my_price( $price, $multiplier, $delivery){
return $price * $multiplier + $delivery;
}

I want to add an additional 3.4% + 20p to the sum of this calculation. What is the simplest way to achieve this?

Thanks.

Just add in the formula like you would when answering a math problem.

Hi astonecipher. Do you mean like this: -

function my_price( $price, $multiplier, $delivery){
return $price * $multiplier + $delivery + 3.4% + 0.2;
}
???

Hello, please recall operator precedence.
https://www.php.net/manual/en/language.operators.precedence.php

so ($x + $y) - $z;

Thanks johnphpnweb.

Whilst I’d love to learn PHP (is on my ever growing list of required learning) I was hoping for more of a ‘just copy/paste this code’ kind of response for now if possible as I need to implement the fix ASAP.

then you should look at freelancer sites like fiverr etc. Forums like these are mostly for helping people who want to learn to code.

2 Likes

i’m not going to code it for you and this is a math problem for you not php. precedence exists from algebra upward, so i suggest you start with math tutorials. Furthermore, i’m a self-help warrior of life. I’m not an educator or a labour-of-love spoon for you to feed from. sorry, mate. I’ve allready assisted you with a tip in the right direction.

I thought this site was called phphelp? Perhaps you should change the name to self-help-don’t ask-us-unless-you-have-all-of-the-skills-you-need-in-which-case-you-don’t-need-to-ask-us. Com

better call it come-here-if-you-want-to-learn-something-and-show-some-affort-to-not-let-others-make-your-personal-work-for-free .com

1 Like

Help, does not mean, code writing service for those not wanting to do it themselves. We help members learn and guide them in problems. We don’t do their work for them, we aren’t your college tutor.

You are just looking for free work, regardless of how small that work is. And if that is the case, I’d invite you to leave.

Sponsor our Newsletter | Privacy Policy | Terms of Service