Adding Order ID to Checkout Success in OpenCart

I needed to add the Order ID for guest checkout in the success page for my OpenCart installation v2.2.0.0

I did not find an extension to do this and the first set of instructions I found did not work. Eventually I got it working using a combination of solutions.

First, you need to edit the success.php file in  catalog\controller\checkout\

Change this:

if (isset($this->session->data['order_id'])) {

Into this:

if (isset($this->session->data['order_id'])) {
 $data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);

Next, you need to edit success.tpl in catalog\view\theme\YOUR-THEME\template\common\

Under the line <h1><?php echo $heading_title; ?></h1>  I added the following:

 <?php if(!empty($orderDetails['order_id'])): ?>
 <h2>OrderID=<?php echo $orderDetails['order_id']; ?></h2>
 <?php endif; ?>

That’s it! When a new order is placed the success page will display the Order ID under Your order has been placed! If the page is refreshed the information goes away because the variable no longer has any value and would generate an error.

Posted in Software Problems & Solutions
4 comments on “Adding Order ID to Checkout Success in OpenCart
  1. Arslan says:

    Hi Admin,

    Thank you so much. I tried it’s working.
    I need your help for showing Total Amount,
    I want to show total amount on that page also. I tried following code but total amount not showing.

    if (isset($this->session->data[‘order_id’])) {
    $data[‘orderDetails’] = $this->model_checkout_order->getOrder($this->session->data[‘order_id’]);
    $data[‘orderAmount’] = $this->cart->getTotal($this->session->data[‘total’]);

    • Ben says:

      Kinda just grasping at straws here but I think you would want to stick with orderDetails instead of changing it to orderAmount. Just change order_id to order_total

      $data[‘orderDetails’] = $this->model_checkout_order->getOrder($this->session->data[‘order_total’]);

      Then you would make is show up by adding
      < ?php echo $orderDetails['order_total']; ?>

  2. rohit mishra says:

    i want to add order status and order total..please help

    • Ben says:

      I just approved and responded to an older comment. Check it out. It may help but I’m not really an expert on this and usually just keep trying things until one works.

      The order status would always be the same wouldn’t it? That could just be static text.

Leave a Reply

Your email address will not be published. Required fields are marked *