tedjmaines:
Still have this issue with new K11a on v157c. I put the proper category for books which is shipped Media Parcel Mail in code as instructed. What it is suppose to do is if anything is NOT a book is put in cart then Media Mail option should not be shown, but on my site Media Mail option is always shown. Anyone have a thought on why??? Thanks.
I had a similar situation. Ajeh (Linda) provided me with a starter routine to permit the exclusion of a class or classes of shipping types depending on the shopping cart contents. To my amazement, that starter code is now in the new version of usps.php, and available for anyone to play with.
With whatever editor program you're using, do a search for " // *** Customizations once per display ***"
The lines after that are as follows:
// bof: example to block USPS Priority MailTM Small Flat Rate Box when anything from master_categories_id 12 or 15 are in the cart
// change false to true to use
if (false) {
$chk_cart = 0;
$chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','12');
$chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','15');
}
// see below use of $chk_cart
// eof: example to block USPS Priority MailTM Small Flat Rate Box when anything from master_categories_id 12 or 15 are in the cart
This was my initial attempt to keep certain things from being shipped in a small flat rate box, and $master_categories_id shown here was the first two categories that I needed to exclude from small flat rate shipping . I have since expanded on this to exclude a wide variety of shipping types, depending on the category or the product or the quantity being ordered. If you want to try this, simply substitute your category number for books for the '12' shown in the example above. You'll need to comment out the next statement if you don't want your category '15' to be similarly affected. And it would be a good idea to substitute the shipping type you're excluding (Media) in the comments, in place of the 'USPS Priority MailTM Small Flat Rate box' verbage. Otherwise, someone (possibly you) is going to be really confused at some point in the future when you need to edit this section or figure out why something isn't working.
There is one more place where you need to insert a few lines. Search for "$type_rebuilt = $type;"
The first few lines after that should read:
// bof: example to block USPS Priority MailTM Small Flat Rate Box when anything from specific master_categories_id are in the cart
// see above for $chk_cart settings
// change false to true to use WAS FALSE
if (true) {
if ($chk_cart > 0 && $type == 'Priority MailTM Small Flat Rate Box') {
// echo 'USPS $type: ' . $type . ' $chk_cart:' . $chk_cart . ', line 575 <br>';
continue;
}
}
// eof: example to block USPS Priority MailTM Small Flat Rate Box when anything from master_categories_id 12 or 15 are in the cart
You'll need to substitute 'MEDIA' where the line above says 'Priority MailTM Small Flat Rate Box.' And you might want to change the wording of the comments so it's refers to Media Mail rather than the Small Flat Rate Box in the code.
The first section of code checks the category number of the items in the cart. If any of them is in a category that could not be shipped by the specified shipping type, then it increments the variable $chk_cart. The second section of code tests $chk_cart to see whether it is greater than zero AND if the shipping type variable ($type) is exactly equal to the value in the quotes. If so, that shipping type will be excluded from the list of shipping types that the customer can choose from.
If you're comfortable tweaking the code, you can expand on this the same way I did, to check for multiple different product or category numbers, for the quantities of certain items, and for whatever else you need to exclude from certain shipping types. Over the years, I've added enough checks that it's very seldom a customer can specify a shipping type unsuitable for the product(s) in the cart. Every test you add will slow down execution just a little bit, of course, so it you have an extremely varied inventory, this may not work well for you. But it has been ideal for us, with a fairly small number of broad categories.