Jump to content

mushroominternet

New Members
  • Posts

    2
  • Joined

  • Last visited

mushroominternet's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The following serialized string is being pulled from the meta data of a Woocommerce product. a:2:{s:17:"set_51fb76f97cc57";a:6:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:14:"trade_customer";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:5:"block";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:0:"";s:2:"to";s:0:"";s:4:"type";s:14:"price_discount";s:6:"amount";s:0:"";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:1:"*";s:6:"adjust";s:1:"1";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:4:"8.37";s:9:"repeating";s:3:"yes";}}}s:17:"set_51fb76f97d6a2";a:6:{s:15:"conditions_type";s:3:"all";s:10:"conditions";a:1:{i:1;a:2:{s:4:"type";s:8:"apply_to";s:4:"args";a:2:{s:10:"applies_to";s:5:"roles";s:5:"roles";a:1:{i:0;s:19:"bulk_trade_customer";}}}}s:9:"collector";a:1:{s:4:"type";s:7:"product";}s:4:"mode";s:5:"block";s:5:"rules";a:1:{i:1;a:4:{s:4:"from";s:0:"";s:2:"to";s:0:"";s:4:"type";s:14:"price_discount";s:6:"amount";s:0:"";}}s:10:"blockrules";a:1:{i:1;a:5:{s:4:"from";s:1:"*";s:6:"adjust";s:1:"1";s:4:"type";s:16:"fixed_adjustment";s:6:"amount";s:5:"9.428";s:9:"repeating";s:3:"yes";}}}} I also have this function which I am writing in order to pull out the variable product data and display it on the site: function mi_price_adjust(){ global $post, $current_user, $user_roles; $meta = get_post_meta($post->ID); $curPrice = (float)$meta['_regular_price'][0]; $variations = unserialize($meta['_pricing_rules'][0]); $user_roles = $current_user->roles; $theRoll = ''; $thePrice = $curPrice; foreach($user_roles as $miroll){ if(in_array($miroll, $user_roles)){ $theRoll = $miroll; } } if($theRoll != ''){ foreach($variations as $curvar){ $var_roll = $curvar['conditions'][1]['args']['roles'][0]; $var_cost = (float)$curvar['blockrules'][1]['amount']; if($var_roll == $theRoll){ $thePrice = $curPrice - $var_cost; } } } if($thePrice != $curPrice){ return "<strike>".$curPrice."</strike><br /><span class=\"youpayText\">You pay £$thePrice</span>"; }else{ return $thePrice; } } Everything is working fine apart from one thing. I am getting the following error: Invalid argument supplied for foreach The line in question is foreach($variations as $curvar){ And the $variations variable is being populated using this: $variations = unserialize($meta['_pricing_rules'][0]); Which returns the serialized string at the top of this post. Can anyone shed any light on why this might be happening and what we might be able to do to either fix it or circumvent it?
  2. I don't think you can get anything that is unique to the computer visiting via PHP. You could drop a cookie on their machine when they visit so you can track them. All you get in $_SERVER is whatever is voluntarily included in the HTTP request so a system based on that would not be more fallible than going down the cookie route. What's the system you are trying to create?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.