Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Shipping formula (Woccommerce)

I ve got a question concerning the shipping formula (>> Flat Rate Shipping >> Costs)

Ho exactly can I use these parameters: [qty], [cost], [fee] ??

Thanks.

12 Answers

Jake Lundberg
Jake Lundberg
13,965 Points

You would need additional information in order to complete the formula as your parameters do not include the cost of shipping...

So is it possible to define several options, e.g.:

  • if the order size is 1-5 items = 5 dollars
  • If the order size larger than 5 then, its 10 dollars ...?
Jake Lundberg
Jake Lundberg
13,965 Points

absolutely. I'm not sure what kind of project you are working, or what exactly you are doing, but yes, you could easily do that.

And how exactly can I set this up ?

Jake Lundberg
Jake Lundberg
13,965 Points

Depends on what you are trying to do...

lets say, I m trying to set up the above example. 1-5 items = 5 dollars , more than 5 items = 10 dollars How do I write the formula? It is menitoned but I cannot find any tutorials on this.

https://dl.dropboxusercontent.com/u/10626022/example.jpg

Jake Lundberg
Jake Lundberg
13,965 Points

that would be a simple if-else statement:

if(quantity > 5) {
   shipping = 10;
} else {
   shipping = 5;
}

so the code goes diractly into a php file ? I thought that is supposed to be typed in the box with the shipping cost price.

Jake Lundberg
Jake Lundberg
13,965 Points

again, it all depends on what you are trying to accomplish. I am only guessing it is an order form for a customer. If that is the case, then you don't want them entering that information into the form themselves. You would handle that in the code behind the scenes with php or javascript or whatever you are using...

I was actually talking about the specific formula that is mentioned here:

https://dl.dropboxusercontent.com/u/10626022/example.jpg

Woocommerce >> Settings >> Flat Rate Shipping

Jake Lundberg
Jake Lundberg
13,965 Points

My apologies, I misunderstood. Looking at the picture, it does not appear you are able to change the shipping cost based on the quantity. Looks like shipping is a flat rate based on this form...So, No, you will not be able to adjust the shipping cost as you have requested unless you are able to modify the code.

Oh OK, thank you very much.