[英]Cant find my error
I am trying to find my error, but this code does not work: 我正在尝试查找我的错误,但是此代码不起作用:
$marginprice = $retProd['price']['FormattedPrice'];
$marginten = '10';
if ($marginprice < $marginten) {$marginprice + '7';}
else {$marginprice + '12';}
update_post_meta($lastId, '_price', $marginprice);
As per the comments, + is not a valid string operator. 根据注释,+不是有效的字符串运算符。
I assume you want to add numbers, in which case you don't need to quote the number: 我假设您要添加数字,在这种情况下,您无需引用数字:
$marginprice = 10;
$marginprice += 7;
echo $marginprice; // will output 17
If you want to concatenate strings (add one after the other): 如果要串联字符串(一个接一个):
$marginprice = 10; // it starts as a number
$marginprice .= '7'; // marginprice is now a string
echo $marginprice; // will output 107
So your code becomes: 因此,您的代码变为:
$marginprice = $retProd['price']['FormattedPrice'];
$marginten = 10;
if ($marginprice < $marginten) {$marginprice += 7;}
else {$marginprice += 12;}
update_post_meta($lastId, '_price', $marginprice);
您需要为变量分配一个值。
$marginprice = $marginprice + 7;
Not sure what you mean by "doesn't work", but you should be using integers for..well..integers, and you are not incrementing marginprice properly: 不知道您所说的“无效”是什么意思,但是您应该对..well..integers使用整数,并且不能正确地增加保证金价格:
$marginprice = $retProd['price']['FormattedPrice'];
$marginten = 10;
if ($marginprice < $marginten) {$marginprice += 7;}
else {$marginprice += 12;}
update_post_meta($lastId, '_price', $marginprice);
If you want to use numbers, you don't need to quote them or they will be interpreted as strings. 如果要使用数字,则无需将其引号,否则它们将被解释为字符串。
$marginprice = $retProd['price']['FormattedPrice'];
$marginten = 10;
if ($marginprice < $marginten)
$marginprice + 7;
else
$marginprice + 12;
update_post_meta($lastId, '_price', $marginprice);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.