I am doing an update in from woocommerce admin, edit order details. I have two problems:
- Only column 'download-count' is updated.
- I am not able to catch any sql errors.
However, when using the same query in a standalone php file, it works fine. What is wrong, and how can I get hold of the sql errors, or at least the query sent?
$table = $wpdb->prefix . 'woocommerce_downloadable_product_permissions';
$expiry_date = date("Y-m-d", strtotime("+ 30 days"));
$expiry_time = $expiry_date . ' 00:00:10';
$wpdb->query("UPDATE `$table` SET
`downloads_remaining` = '1',
`access_expires` = '$expiry_time',
`download_count` = (`download_count` + 1)
WHERE `order_id` = '$post_id'");
Here is "standalone php version, which works:
$link = mysqli_connect($servername, $username, $password, $db);
$post_id = '219';
if (!$link) { exit; }
$expiry_date = date("Y-m-d", strtotime("+ 30 days"));
$expiry_time = $expiry_date . ' 00:00:00';
$table = 'hkmw_woocommerce_downloadable_product_permissions';
$query = "UPDATE `$table` SET
`downloads_remaining` = '1',
`access_expires` = '$expiry_time',
`download_count` = (`download_count` + 1)
WHERE `order_id` = '$post_id';";
if (!mysqli_query($link,$query)) {
printf("Errormessage: %s\n", mysqli_error($link));
}
mysqli_close($link);
$wpdb
has anupdate
method you might want to use to improve the readability