Shopping Cart PHP Algorithms
When working with shipping methods, developers are able to code custom PHP algorithms to calculate pricing. Below you will find some common examples.
To configure a custom PHP algorithm for a shipping method, navigate to:
Dashboard > Settings > Commerce > Shipping Methods > New Shipping Method.
When creating the new shipping method, select the "Custom PHP Algorithm" pricing option.
Example One: Using Postcodes
A florist charges $10 delivery to suburbs nearby, $20 to suburbs slightly further away, otherwise a flat rate of $30. Shipping is calculated per cart, not per item.
Example Two: Using Weight
An online retailer ships heavy items around the country (eg. trampolines and accessories). A delivery fee is calculated based on the weight of the products.
Charge $25 per item under 10kg, and $40 per item between 10-20kg. Where items in the cart are over 20kg, throw an error asking the user to request a quote.
Charge per item in the shopping cart, rather than a flat total for the entire cart.
Example Three: Using Product Categories
An electronics store charges based on the Product Category of the Products in the shopping cart.
Charge $200 delivery for Desks, and $150 for Computers (where Desks and Computers are the Product Categories). Otherwise charge $50.