WordPress.org

Ready to get started?Download WordPress

Forums

Simple Cart & Buy Now
[resolved] controlling weight using options? (15 posts)

  1. wesleyblack12
    Member
    Posted 9 months ago #

    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

    description:price:weight

    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.

    http://wordpress.org/extend/plugins/simple-cart-buy-now/

  2. wesleyblack12
    Member
    Posted 9 months ago #

    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.

  3. bluey80
    Member
    Plugin Author

    Posted 9 months ago #

    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).

  4. wesleyblack12
    Member
    Posted 9 months ago #

    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.

  5. bluey80
    Member
    Plugin Author

    Posted 9 months ago #

    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"]

  6. wesleyblack12
    Member
    Posted 9 months ago #

    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.

  7. bluey80
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  8. wesleyblack12
    Member
    Posted 9 months ago #

    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.

  9. wesleyblack12
    Member
    Posted 9 months ago #

    Oh, that's where I was stumped previously...

    remove_filter('scabn_getItemWeight',array($this,'getItemWeight'),10,3);
    add_filter('scabn_getItemWeight','getItemWeight',10,3);
    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){
    		$weight=20;
    	} 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?

  10. bluey80
    Member
    Plugin Author

    Posted 9 months ago #

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

  11. wesleyblack12
    Member
    Posted 9 months ago #

    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:
    3-x-4-5-fabu-gloss-bottleneck-hangers-44-16000

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

    remove_filter('scabn_getItemWeight',array($this,'getItemWeight'),10,3);
    add_filter('scabn_getItemWeight','getItemWeight',10,3);
    function getItemWeight($itemname,$qty,$inputweight) {	
    
    	echo "itemname = $itemname";
    }
  12. bluey80
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  13. wesleyblack12
    Member
    Posted 9 months ago #

    Thanks for the quick reply. That makes sense. :)

  14. wesleyblack12
    Member
    Posted 9 months ago #

    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.

  15. bluey80
    Member
    Plugin Author

    Posted 9 months ago #

    Cool. Glad it's working.

Reply

You must log in to post.

About this Plugin

About this Topic