gpratt86 gpratt86 - 5 months ago 26
PHP Question

Issue with CI order status

This is written in

CI
and using the
wooapi v2
. The order is always being marked as
completed
, instead of
manual renewal
. The goal is that if the post status is already manual renewal, that it will not get marked completed, but stay manual renewal. Any help greatly appreciated. Somewhat new to 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');
}
}
}

Answer

You have a couple of mistakes/typos in your code here

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');
}

You are assigning = instead of comparing === which will always return true, and I guess this should be a string, not a constant: 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');
}
Comments