Opencart cancel order by customer?

Opencart cancel order by customer?

How exactly to cancel an order by customer in Opencart?

By default, there is no possibility that the customer to cancel an order from his account.

The administrator of the store can do that from the admin panel.

However, in this article, we will show you how to improvise something in order to add a cancel button for every order.


So the customer can directly cancel his orders from his account.

Opencart cancel order by customer first step:

You need to edit the file called order_list.tpl.

This is found in catalog/view/theme/default/template/account/order_list.tpl.

Replace “default” if you are using a custom theme.


In order_list.tpl, you need to add after the code:

1
<td class="text-right"><?php echo $order['total']; ?></td>

add:

2
3
4
<td class="text-right">
<a href="cancel-order-446645756323.php?order_id=<?php echo $order['order_id']; ?>" class="btn btn-danger" onclick="return confirm('Are you sure?')">Cancel order, nr <?php echo $order['order_id']; ?></a>
</td>

That is all here, you can customize this text and html code as you please.

One more step.

You need to create a php file and upload it into the root of your domain (example root domain: “https://incvice.com/”);


Name the php file “cancel-order-446645756323.php”.

Inside “cancel-order-446645756323.php”, add the following code, you don’t have to edit anything from the following code:

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php session_start(); ?>
<?php 
$customer_id = $_SESSION['default']['customer_id'];
if ($customer_id == ''){
exit;
}
//echo $customer_id;
 
$order_id = mysql_escape_string($_GET['order_id']);
if ($order_id == ''){
exit;	
}
include 'config.php';
	$link = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
	mysql_select_db(DB_DATABASE); 
	if (!$link) {
    	die('Could not connect: ' . mysql_error());
	}
$updateSQL = mysql_query("UPDATE oc_order SET order_status_id = '7' where order_id = '$order_id;' and customer_id = '$customer_id'");
 
?>
<script>alert("The order was canceled!");
window.location.replace('/')
</script>

This is the page that will make the order to be canceled.

If you have some php knowledge, you can understand the code, if not, just copy and paste it there.

Make an order as a normal customer user on your Opencart website and then go to “my orders”.


You will see the button to cancel, click it and proceed to cancel the order.

All it takes is a few seconds.

After you have canceled the order, the order should appear as canceled inside the admin panel, at sales and also from the widget from the first page.

This was tested on Opencart 2.1.0.2 but it should work on older and newer Opencart versions.

If you don’t manage to do all these changes, you can contact us and we will do them for a very small fee, starting from 10$.

Use the contact page from the website or leave a comment in the comment section.

Add a comment: