Support » Plugin: Simple Cart & Buy Now » controlling weight using options?

  • Resolved wesleyblack12


    I’m trying to add a weight field to each option in the drop down.

    My guess is that I need to modify the way the short code works in able to do this.

    I would think that I could add a third value to the array, such as


    Unfortunately, when I tried going this route, it turned out to be a little too complex for me to figure out.

    Have you any insights you can send my way? I’m trying to get product weight from the drop-down (option fields) to the shopping cart.

Viewing 14 replies - 1 through 14 (of 14 total)
  • I have read through your default.php file, which has some useful information and code examples. I think that this getItemWeight function may be of use in this case.

    However, I think I’ll still need to add an extra field in order to pull it off.

    Looking forward to some guidance.

    Plugin Author bluey80


    I’m not sure I’m understanding what you are trying to do — do you want to user to select the weight (buying flour, 1lb, 2lb or 3lb) or do you want Paypal to know the weight of what the customer is buying (Item1 weights 1lb, Item2, 2 lbs, etc).

    Each option has both a unique price and weight.
    These are printed products, so it would be….
    (qty1:$100:10lbs, qty2:$200:20lbs, etc)

    I hope this helps clarify.

    Plugin Author bluey80


    I’m still not understanding. The weight field is per-unit. So there is no need to store qty1=10lbs, qty2=20lbs. You just say weight=10 in the shortcode. Same with price. So what options do you want the user to select? Quantity? Weight? Not price.

    Take a look at this item shortcode for an example of options with different prices, maybe that is what you want.

    [scabn name=”Item” options_name=”Weight” options=”40lbs:20,80lbs:40,120lbs:50″ qty_field = “true” b_title=”Add To Cart”]

    I understand the reason for confusion.
    A particular product has 5 qtys available. each with different weights and prices.

    the qtys are for printed materials… so per unit weight calculations won’t work.

    for example: 4,000 qty weighs 30 lbs.

    each qty is actually a product. print qty has to be treated like an option. and is different from item quantity.

    for example: the customer may order 3 sets of 1,000 pieces each set costing $100 and each weighing 30lbs.

    Plugin Author bluey80


    Ok, here’s the solution, I believe:

    [scabn name=”Item” options_name=”qty” options=”4000:20,6000:35,7500:50″ qty_field = “true” b_title=”Add To Cart”]

    This will create options based on quantity 4,000 or 6,000 etc

    As for weight, if you need to set that, you will need to do that on backend with a function. Take a look at getItemWeight in templates/default.php — you will want to make your own template and edit that function to do some lookup to get weight for different quantites of products.

    I thought about that as well. I’ll just need to update the item name to be a little more descriptive so my db lookup will work.

    Thanks for the suggestion. I’ll check back and let you know if I have success.

    Oh, that’s where I was stumped previously…

    function getItemWeight($itemname,$qty,$inputweight) {
    	//Note: Paypal doesn't like a weight of zero, this makes
    	//sure weight it at least 0.01
    	if ($qty > 10){
    	} else {
    		$weight = $inputweight;
    	if ($weight <= 0.01) {
    		$weight = 0.01;
    	return $weight;

    This function does not appear to receive the selected option. (which would include the qty selected)

    Am I right?

    Plugin Author bluey80


    I believe $itenname should be “itemname_selectedOption” or something like that so you do have access to the option (qty) selected.

    You’re right… the option is appended.

    I’m running into an issue though…

    it converts this:
    3 x 4.5 Fabu-Gloss Bottleneck Hangers 4/4 16000
    to this:

    Is there some kind of filter at work? I’m losing many important delimiters.

    function getItemWeight($itemname,$qty,$inputweight) {	
    	echo "itemname = $itemname";
    Plugin Author bluey80


    Yes that is normal and intentional just so weird / bad things can’t be encoded in the name when it gets into the php backend. And when you are doing string comparisons you don’t need to be case sensitive, use spaces, etc.

    But this shouldn’t affect how the user sees the options — this is just an internal reference to the product so you can lookup the weight in a lookup table or something like that. getItemWeight only returns the weight, so it doesn’t need to know the nice display-ready version of the product name.

    Thanks for the quick reply. That makes sense. 🙂

    OK, GREAT!

    I have managed to pull the correct weight from the database.

    Learned some new SQL tricks along the way.

    THANKS VERY MUCH for your help.

    Plugin Author bluey80


    Cool. Glad it’s working.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘controlling weight using options?’ is closed to new replies.