The issue is that the order list isn't being cleared after payment because the query is fetching all orders regardless of status. We need to modify the query to only show pending orders. Here's the fix:
The key changes made are:
WHERE o.status = 'Pending'I'll help you fix the cancel functionality. The issue is that while the cancel logic exists, we need to ensure the order list refreshes properly after cancellation. Here's the updated code:
Key improvements made:
The cancellation process now:
I'll help you implement the "x" button functionality to cancel products from the order list and restore their stock quantities. Here's the updated code:
Key changes made:
Enhanced the handleOrderListActions function to:
removeFromOrderCart functionUpdated the removeFromOrderCart function to:
The cancel button functionality now:
The rest of the code remains exactly the same. This implementation ensures that when you click the "x" button:
I'll help you integrate the "x" button functionality to cancel individual products from the order list. Here's the modified code:
Key changes made:
Modified the cancel order functionality to:
Updated the order list table to:
Added CSS styling for the remove button
Improved the confirmation message to be more specific
Only show the Pay button when there are pending orders
The functionality now allows you to:
I'll explain the specific code modifications I made to implement the "x" button functionality for canceling individual products from the order list:
Original Code:
if (isset($_POST['cancel_order'])) {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
// ... canceled entire order ...
}
if (isset($_POST['cancel_order'])) {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
// ... canceled entire order ...
}
Modified Code:
if (isset($_POST['cancel_order'])) {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
$product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0;
if ($order_id && $product_id) {
// Get the specific order item to cancel
$order_item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.*, p.name AS product_name
FROM $table_name_order_items oi
JOIN $table_name_products p ON oi.product_id = p.id
WHERE order_id = %d AND product_id = %d",
$order_id,
$product_id
));
if ($order_item) {
// Restore product stock
$product = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name_products WHERE id = %d", $product_id));
if ($product) {
$new_stock = $product->{'in_stock'} + $order_item->quantity;
$wpdb->update($table_name_products, ['in_stock' => $new_stock], ['id' => $product_id]);
// ... logging code ...
}
// Delete the specific order item
$wpdb->delete($table_name_order_items, [
'order_id' => $order_id,
'product_id' => $product_id
]);
// Check if this was the last item in the order
$remaining_items = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table_name_order_items WHERE order_id = %d",
$order_id
));
if ($remaining_items == 0) {
// Delete the order if no items left
$wpdb->delete($table_name_orders, ['id' => $order_id]);
// ... logging code ...
}
// ... redirect code ...
}
}
}
if (isset($_POST['cancel_order'])) {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
$product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0;
if ($order_id && $product_id) {
// Get the specific order item to cancel
$order_item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.*, p.name AS product_name
FROM $table_name_order_items oi
JOIN $table_name_products p ON oi.product_id = p.id
WHERE order_id = %d AND product_id = %d",
$order_id,
$product_id
));
if ($order_item) {
// Restore product stock
$product = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name_products WHERE id = %d", $product_id));
if ($product) {
$new_stock = $product->{'in_stock'} + $order_item->quantity;
$wpdb->update($table_name_products, ['in_stock' => $new_stock], ['id' => $product_id]);
// ... logging code ...
}
// Delete the specific order item
$wpdb->delete($table_name_order_items, [
'order_id' => $order_id,
'product_id' => $product_id
]);
// Check if this was the last item in the order
$remaining_items = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table_name_order_items WHERE order_id = %d",
$order_id
));
if ($remaining_items == 0) {
// Delete the order if no items left
$wpdb->delete($table_name_orders, ['id' => $order_id]);
// ... logging code ...
}
// ... redirect code ...
}
}
}
Original Code:
<td>
<form method="post" action="" style="display: inline;">
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<button type="submit" name="cancel_order" onclick="return confirm('Are you sure you want to cancel this order?');">Cancel</button>
</form>
</td>
<td>
<form method="post" action="" style="display: inline;">
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<button type="submit" name="cancel_order" onclick="return confirm('Are you sure you want to cancel this order?');">Cancel</button>
</form>
</td>
Modified Code:
<td>
<form method="post" action="" style="display: inline;">
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<input type="hidden" name="product_id" value="<?php echo esc_attr($order['product_id']); ?>">
<button type="submit" name="cancel_order" class="remove-item-btn" title="Remove this item" onclick="return confirm('Are you sure you want to remove this item? The quantity will be restored to stock.');">
<i class="fas fa-times"></i>
</button>
</form>
</td>
<td>
<form method="post" action="" style="display: inline;">
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<input type="hidden" name="product_id" value="<?php echo esc_attr($order['product_id']); ?>">
<button type="submit" name="cancel_order" class="remove-item-btn" title="Remove this item" onclick="return confirm('Are you sure you want to remove this item? The quantity will be restored to stock.');">
<i class="fas fa-times"></i>
</button>
</form>
</td>
New CSS:
.remove-item-btn {
background: #dc3545;
color: white;
border: none;
border-radius: 50%;
cursor: pointer;
padding: 0;
width: 22px;
height: 22px;
font-size: 0.8em;
line-height: 22px;
text-align: center;
}
.remove-item-btn:hover {
background: #c82333;
}
.remove-item-btn {
background: #dc3545;
color: white;
border: none;
border-radius: 50%;
cursor: pointer;
padding: 0;
width: 22px;
height: 22px;
font-size: 0.8em;
line-height: 22px;
text-align: center;
}
.remove-item-btn:hover {
background: #c82333;
}
Granular Cancellation:
order_id and product_id to identify specific itemsStock Restoration:
Order Cleanup:
Improved UI:
Conditional Pay Button:
These changes make the cancellation process more precise while maintaining all the existing functionality like inventory tracking and logging. The UI is now more intuitive with the "x" button clearly indicating the remove action for each product.*
Yes! Here are the specific code snippets you should insert in place of the // ... logging code ... and // ... redirect code ... comments:
// Log the stock restoration
log_inventory_action(
'update',
'product',
$order_item->product_name,
"Restored {$order_item->quantity} units of {$order_item->product_name} from order #{$order_id}. New stock: {$new_stock}"
);
// Log the stock restoration
log_inventory_action(
'update',
'product',
$order_item->product_name,
"Restored {$order_item->quantity} units of {$order_item->product_name} from order #{$order_id}. New stock: {$new_stock}"
);
// Log the order cancellation
log_inventory_action(
'delete',
'order',
"Order #{$order_id}",
"Cancelled order #{$order_id} as all items were removed"
);
// Log the order cancellation
log_inventory_action(
'delete',
'order',
"Order #{$order_id}",
"Cancelled order #{$order_id} as all items were removed"
);
wp_redirect($_SERVER['REQUEST_URI']);
exit;
wp_redirect($_SERVER['REQUEST_URI']);
exit;
Here's how the complete code block should look with all pieces integrated:
if (isset($_POST['cancel_order'])) {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
$product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0;
if ($order_id && $product_id) {
// Get the specific order item to cancel
$order_item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.*, p.name AS product_name
FROM $table_name_order_items oi
JOIN $table_name_products p ON oi.product_id = p.id
WHERE order_id = %d AND product_id = %d",
$order_id,
$product_id
));
if ($order_item) {
// Restore product stock
$product = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name_products WHERE id = %d", $product_id));
if ($product) {
$new_stock = $product->{'in_stock'} + $order_item->quantity;
$wpdb->update($table_name_products, ['in_stock' => $new_stock], ['id' => $product_id]);
// Log the stock restoration
log_inventory_action(
'update',
'product',
$order_item->product_name,
"Restored {$order_item->quantity} units of {$order_item->product_name} from order #{$order_id}. New stock: {$new_stock}"
);
}
// Delete the order item
$wpdb->delete($table_name_order_items, [
'order_id' => $order_id,
'product_id' => $product_id
]);
// Check if this was the last item in the order
$remaining_items = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table_name_order_items WHERE order_id = %d",
$order_id
));
if ($remaining_items == 0) {
// Delete the order if no items left
$wpdb->delete($table_name_orders, ['id' => $order_id]);
// Log the order cancellation
log_inventory_action(
'delete',
'order',
"Order #{$order_id}",
"Cancelled order #{$order_id} as all items were removed"
);
}
wp_redirect($_SERVER['REQUEST_URI']);
exit;
}
}
}
if (isset($_POST['cancel_order'])) {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
$product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0;
if ($order_id && $product_id) {
// Get the specific order item to cancel
$order_item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.*, p.name AS product_name
FROM $table_name_order_items oi
JOIN $table_name_products p ON oi.product_id = p.id
WHERE order_id = %d AND product_id = %d",
$order_id,
$product_id
));
if ($order_item) {
// Restore product stock
$product = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name_products WHERE id = %d", $product_id));
if ($product) {
$new_stock = $product->{'in_stock'} + $order_item->quantity;
$wpdb->update($table_name_products, ['in_stock' => $new_stock], ['id' => $product_id]);
// Log the stock restoration
log_inventory_action(
'update',
'product',
$order_item->product_name,
"Restored {$order_item->quantity} units of {$order_item->product_name} from order #{$order_id}. New stock: {$new_stock}"
);
}
// Delete the order item
$wpdb->delete($table_name_order_items, [
'order_id' => $order_id,
'product_id' => $product_id
]);
// Check if this was the last item in the order
$remaining_items = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table_name_order_items WHERE order_id = %d",
$order_id
));
if ($remaining_items == 0) {
// Delete the order if no items left
$wpdb->delete($table_name_orders, ['id' => $order_id]);
// Log the order cancellation
log_inventory_action(
'delete',
'order',
"Order #{$order_id}",
"Cancelled order #{$order_id} as all items were removed"
);
}
wp_redirect($_SERVER['REQUEST_URI']);
exit;
}
}
}
Logging Details:
Redirect:
wp_redirect() to refresh the pageexit is crucial after redirect to stop further executionSecurity:
absint()Context:
This implementation maintains all the existing functionality while adding the granular product cancellation feature with proper logging and inventory management.*_
Let me help you troubleshoot the issue. Here's a step-by-step solution to make the cancel button work properly:
<td>
<form method="post" action="" style="display: inline;">
<?php wp_nonce_field('cancel_order_action', '_wpnonce_cancel_order'); ?>
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<input type="hidden" name="product_id" value="<?php echo esc_attr($order['product_id']); ?>">
<button type="submit" name="cancel_order" class="remove-item-btn"
onclick="return confirm('Remove this item? Quantity will be restored to stock.');">
<i class="fas fa-times"></i>
</button>
</form>
</td>
<td>
<form method="post" action="" style="display: inline;">
<?php wp_nonce_field('cancel_order_action', '_wpnonce_cancel_order'); ?>
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<input type="hidden" name="product_id" value="<?php echo esc_attr($order['product_id']); ?>">
<button type="submit" name="cancel_order" class="remove-item-btn"
onclick="return confirm('Remove this item? Quantity will be restored to stock.');">
<i class="fas fa-times"></i>
</button>
</form>
</td>
if (isset($_POST['cancel_order'])) {
// Verify nonce first
if (!isset($_POST['_wpnonce_cancel_order']) || !wp_verify_nonce($_POST['_wpnonce_cancel_order'], 'cancel_order_action')) {
$message = 'Security check failed!';
} else {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
$product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0;
if ($order_id && $product_id) {
// Get the specific order item
$order_item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.*, p.name AS product_name, p.in_stock
FROM $table_name_order_items oi
JOIN $table_name_products p ON oi.product_id = p.id
WHERE oi.order_id = %d AND oi.product_id = %d",
$order_id,
$product_id
));
if ($order_item) {
// Restore stock
$new_stock = $order_item->in_stock + $order_item->quantity;
$wpdb->update(
$table_name_products,
['in_stock' => $new_stock],
['id' => $product_id]
);
// Log the action
log_inventory_action(
'update',
'product',
$order_item->product_name,
"Restored {$order_item->quantity} units of {$order_item->product_name} (Order #{$order_id}). New stock: {$new_stock}"
);
// Delete the order item
$wpdb->delete(
$table_name_order_items,
[
'order_id' => $order_id,
'product_id' => $product_id
],
['%d', '%d']
);
// Check if order is now empty
$remaining_items = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table_name_order_items WHERE order_id = %d",
$order_id
));
if ($remaining_items == 0) {
$wpdb->delete($table_name_orders, ['id' => $order_id], ['%d']);
log_inventory_action(
'delete',
'order',
"Order #{$order_id}",
"Order cancelled - all items removed"
);
}
wp_redirect(remove_query_arg(['added', 'updated'], $_SERVER['REQUEST_URI']));
exit;
}
}
}
}
if (isset($_POST['cancel_order'])) {
// Verify nonce first
if (!isset($_POST['_wpnonce_cancel_order']) || !wp_verify_nonce($_POST['_wpnonce_cancel_order'], 'cancel_order_action')) {
$message = 'Security check failed!';
} else {
$order_id = isset($_POST['order_id']) ? absint($_POST['order_id']) : 0;
$product_id = isset($_POST['product_id']) ? absint($_POST['product_id']) : 0;
if ($order_id && $product_id) {
// Get the specific order item
$order_item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.*, p.name AS product_name, p.in_stock
FROM $table_name_order_items oi
JOIN $table_name_products p ON oi.product_id = p.id
WHERE oi.order_id = %d AND oi.product_id = %d",
$order_id,
$product_id
));
if ($order_item) {
// Restore stock
$new_stock = $order_item->in_stock + $order_item->quantity;
$wpdb->update(
$table_name_products,
['in_stock' => $new_stock],
['id' => $product_id]
);
// Log the action
log_inventory_action(
'update',
'product',
$order_item->product_name,
"Restored {$order_item->quantity} units of {$order_item->product_name} (Order #{$order_id}). New stock: {$new_stock}"
);
// Delete the order item
$wpdb->delete(
$table_name_order_items,
[
'order_id' => $order_id,
'product_id' => $product_id
],
['%d', '%d']
);
// Check if order is now empty
$remaining_items = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM $table_name_order_items WHERE order_id = %d",
$order_id
));
if ($remaining_items == 0) {
$wpdb->delete($table_name_orders, ['id' => $order_id], ['%d']);
log_inventory_action(
'delete',
'order',
"Order #{$order_id}",
"Order cancelled - all items removed"
);
}
wp_redirect(remove_query_arg(['added', 'updated'], $_SERVER['REQUEST_URI']));
exit;
}
}
}
}
Check Form Submission:
// Temporarily add at the top of your cancel handler
echo '<pre>'; print_r($_POST); die;
// Temporarily add at the top of your cancel handler
echo '<pre>'; print_r($_POST); die;
Verify you're receiving both order_id and product_id.
Verify Database Queries:
// After your query, check if it returned results
if (!$order_item) {
$message = 'Order item not found! Query: ' . $wpdb->last_query;
}
// After your query, check if it returned results
if (!$order_item) {
$message = 'Order item not found! Query: ' . $wpdb->last_query;
}
Check for Errors:
// After your update/delete operations
if (false === $wpdb->delete(...)) {
$message = 'Delete failed: ' . $wpdb->last_error;
}
// After your update/delete operations
if (false === $wpdb->delete(...)) {
$message = 'Delete failed: ' . $wpdb->last_error;
}
Verify Redirect:
Make sure there's no output before wp_redirect(). Add this check:
if (headers_sent()) {
$message = 'Headers already sent, cannot redirect';
} else {
wp_redirect(...);
exit;
}
if (headers_sent()) {
$message = 'Headers already sent, cannot redirect';
} else {
wp_redirect(...);
exit;
}
Not Redirecting Properly:
wp_redirect()exit immediately after redirectDatabase Operations Failing:
Nonce Verification Failing:
cancel_order_action)_wpnonce_cancel_order)Stock Not Updating:
in_stock column name is correctWould you like me to focus on any specific part of this solution? Or do you need help debugging a particular issue you're encountering?_
Let me help you systematically identify why the cancel button isn't working. Here are the most common issues and how to fix them:
Temporarily add this at the TOP of your PHP file (right after session_start()):
// Debugging code - remove after testing
if (isset($_POST['cancel_order'])) {
echo '<pre>POST DATA: '; print_r($_POST); echo '</pre>';
echo 'Nonce valid: '.(wp_verify_nonce($_POST['_wpnonce_cancel_order'] ?? '', 'cancel_order_action') ? 'Yes' : 'No');
die();
}
// Debugging code - remove after testing
if (isset($_POST['cancel_order'])) {
echo '<pre>POST DATA: '; print_r($_POST); echo '</pre>';
echo 'Nonce valid: '.(wp_verify_nonce($_POST['_wpnonce_cancel_order'] ?? '', 'cancel_order_action') ? 'Yes' : 'No');
die();
}
Symptoms: The debug output shows empty POST data
Fix:
<form method="post" action="">
<?php wp_nonce_field('cancel_order_action', '_wpnonce_cancel_order'); ?>
<!-- hidden inputs and button -->
</form>
<form method="post" action="">
<?php wp_nonce_field('cancel_order_action', '_wpnonce_cancel_order'); ?>
<!-- hidden inputs and button -->
</form>
Symptoms: Debug shows "Nonce valid: No"
Fix:
// In form:
wp_nonce_field('cancel_order_action', '_wpnonce_cancel_order');
// In handler:
wp_verify_nonce($_POST['_wpnonce_cancel_order'], 'cancel_order_action')
// In form:
wp_nonce_field('cancel_order_action', '_wpnonce_cancel_order');
// In handler:
wp_verify_nonce($_POST['_wpnonce_cancel_order'], 'cancel_order_action')
Symptoms: No database changes occur
Fix:
$result = $wpdb->update(...);
if (false === $result) {
error_log('Update failed: '.$wpdb->last_error);
}
$result = $wpdb->delete(...);
if (false === $result) {
error_log('Delete failed: '.$wpdb->last_error);
}
$result = $wpdb->update(...);
if (false === $result) {
error_log('Update failed: '.$wpdb->last_error);
}
$result = $wpdb->delete(...);
if (false === $result) {
error_log('Delete failed: '.$wpdb->last_error);
}
echo "Using table: {$wpdb->prefix}order_items";
echo "Using table: {$wpdb->prefix}order_items";
Symptoms: Page doesn't refresh after cancel
Fix:
// At very top of file:
ob_start();
// When redirecting:
ob_end_clean();
wp_redirect($_SERVER['REQUEST_URI']);
exit;
// At very top of file:
ob_start();
// When redirecting:
ob_end_clean();
wp_redirect($_SERVER['REQUEST_URI']);
exit;
Symptoms: Products disappear but stock doesn't update
Fix:
$updated = $wpdb->update(
$table_name_products,
['in_stock' => $new_stock],
['id' => $product_id],
['%d'], // Format for value
['%d'] // Format for where
);
$updated = $wpdb->update(
$table_name_products,
['in_stock' => $new_stock],
['id' => $product_id],
['%d'], // Format for value
['%d'] // Format for where
);
<td>
<form method="post" action="">
<?php wp_nonce_field('cancel_order_action_'.$order['id'], '_wpnonce_cancel_order'); ?>
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<input type="hidden" name="product_id" value="<?php echo esc_attr($order['product_id']); ?>">
<button type="submit" name="cancel_order" class="remove-item-btn"
onclick="return confirm('Remove this item?');">
<i class="fas fa-times"></i>
</button>
</form>
</td>
<td>
<form method="post" action="">
<?php wp_nonce_field('cancel_order_action_'.$order['id'], '_wpnonce_cancel_order'); ?>
<input type="hidden" name="order_id" value="<?php echo esc_attr($order['id']); ?>">
<input type="hidden" name="product_id" value="<?php echo esc_attr($order['product_id']); ?>">
<button type="submit" name="cancel_order" class="remove-item-btn"
onclick="return confirm('Remove this item?');">
<i class="fas fa-times"></i>
</button>
</form>
</td>
if (isset($_POST['cancel_order'])) {
// Verify nonce with order_id for better security
if (!wp_verify_nonce($_POST['_wpnonce_cancel_order'] ?? '', 'cancel_order_action_'.($_POST['order_id'] ?? 0))) {
$message = 'Security verification failed!';
} else {
$order_id = absint($_POST['order_id'] ?? 0);
$product_id = absint($_POST['product_id'] ?? 0);
if ($order_id && $product_id) {
// Get item details
$item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.quantity, p.name, p.in_stock
FROM {$table_name_order_items} oi
JOIN {$table_name_products} p ON oi.product_id = p.id
WHERE oi.order_id = %d AND oi.product_id = %d",
$order_id, $product_id
));
if ($item) {
// Restore stock
$wpdb->update(
$table_name_products,
['in_stock' => $item->in_stock + $item->quantity],
['id' => $product_id],
['%d'],
['%d']
);
// Remove item
$wpdb->delete(
$table_name_order_items,
['order_id' => $order_id, 'product_id' => $product_id],
['%d', '%d']
);
// Check if order is empty
$remaining = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM {$table_name_order_items} WHERE order_id = %d",
$order_id
));
if (!$remaining) {
$wpdb->delete($table_name_orders, ['id' => $order_id], ['%d']);
}
wp_safe_redirect(remove_query_arg(['added', 'updated'], wp_get_referer()));
exit;
}
}
}
}
if (isset($_POST['cancel_order'])) {
// Verify nonce with order_id for better security
if (!wp_verify_nonce($_POST['_wpnonce_cancel_order'] ?? '', 'cancel_order_action_'.($_POST['order_id'] ?? 0))) {
$message = 'Security verification failed!';
} else {
$order_id = absint($_POST['order_id'] ?? 0);
$product_id = absint($_POST['product_id'] ?? 0);
if ($order_id && $product_id) {
// Get item details
$item = $wpdb->get_row($wpdb->prepare(
"SELECT oi.quantity, p.name, p.in_stock
FROM {$table_name_order_items} oi
JOIN {$table_name_products} p ON oi.product_id = p.id
WHERE oi.order_id = %d AND oi.product_id = %d",
$order_id, $product_id
));
if ($item) {
// Restore stock
$wpdb->update(
$table_name_products,
['in_stock' => $item->in_stock + $item->quantity],
['id' => $product_id],
['%d'],
['%d']
);
// Remove item
$wpdb->delete(
$table_name_order_items,
['order_id' => $order_id, 'product_id' => $product_id],
['%d', '%d']
);
// Check if order is empty
$remaining = $wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM {$table_name_order_items} WHERE order_id = %d",
$order_id
));
if (!$remaining) {
$wpdb->delete($table_name_orders, ['id' => $order_id], ['%d']);
}
wp_safe_redirect(remove_query_arg(['added', 'updated'], wp_get_referer()));
exit;
}
}
}
}
Would you like me to focus on any specific part of this troubleshooting?*