这是用CI
写的,并使用wooapi v2
。订单始终标记为completed
,而不是manual renewal
。目标是,如果帖子状态已经手动续订,它将不会标记为已完成,但保持手动续订。任何帮助非常感谢。 CI有点新鲜。
function complete_order($orderid) {
$consumer_key = 'xxx'; // Add your own Consumer Key here
$consumer_secret = 'xxxx'; // Add your own Consumer Secret here
$store_url = 'xxx'; // Add the home URL to the store you want to connect to here
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql ="SELECT * FROM xxxxxx WHERE ID = '$orderid'";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$poststatus= '. $row["post_status"].';
if ($poststatus = wc-manual-renewal-re){
$client = new WC_API_Client($store_url, $consumer_key, $consumer_secret, $options);
$client->orders->update_status($orderid, 'wc-manual-renewal-re');
}else{$client = new WC_API_Client($store_url, $consumer_key, $consumer_secret, $options);
$client->orders->update_status($orderid, 'wc-completed');
}
}
}
答案 0 :(得分:0)
您的代码中有几处错误/拼写错误
if ($poststatus = wc-manual-renewal-re){
$client = new WC_API_Client($store_url, $consumer_key, $consumer_secret, $options);
$client->orders->update_status($orderid, 'wc-manual-renewal-re');
}
您指定=
而不是比较===
,它总是返回true,我想这应该是一个字符串,而不是常量:wc-manual-renewal-re
if ($poststatus === 'wc-manual-renewal-re'){
$client = new WC_API_Client($store_url, $consumer_key, $consumer_secret, $options);
$client->orders->update_status($orderid, 'wc-manual-renewal-re');
}