How To (Ubercart): Create a shipping "weight limit" message to the shopper
Problem
A client requested to show an error message on the /cart and cart/checkout page when the order shipping weight is greater than 500lbs. They are shipping grass seed and need the purchaser to complete the order over the phone.
Options
I did try using workflow-ng first but with this ubercart install some of the workflow options were not in place. I love workflow but I don't dig to deep into the code. I wanted another solution.
You could create a custom module and check the total weight when on /cart and /cart/checkout too. If this was my personal site this is the solution I would of selected.
Another option is more basic. Create a block and use PHP to do the work. This is the option I choose. If the client has a need for a custom module to override other module stuff then we can always move this solution to the module.
SolutionFirst you need to create a block and set it up to only show up on
- cart
- cart/checkout
- cart/checkout/*
There is no need for a block title, so disregard that. Once done, for the block body you will use the following code. Be sure to choose PHP for the input format!
<?php
$items = uc_cart_get_contents();
foreach($items as $item) {
$weights += ($item->qty * $item->weight);
}
$total_weight = $weights;
if($total_weight > '500') {
drupal_set_message("Your message here...", 'error');
}
?>
Now click save and give it a test run.
Enjoy!
Comments
Hey Elvis, Clever and quick
@SoyaWaxJim, Hi, I did end
Hey, again, Elvis, Actually,
Elvis, so far I used your
Glad to hear others getting
Add new comment