How To Run Some Javascript Code When Order Status Changes

I wan to run some javascript code for a tracker when the status of the order changes to say Complete

Where can i add this code ?

{literal}
{/literal}

I wan to run some javascript code for a tracker when the status of the order changes to say Complete

Where can i add this code ?

{literal}
{/literal}

Hello!

You can place this code on the order complete page, but the order status will not be Complete, but the status returned by your payment gateway.

To do this you can create the HTML block with Smarty support on this page in the layouts.

I think i was not clear in my request.

I want to run this code when the status of the Order Changes to Complete from Delivered. This status change will happen from the backend and when the status change happens then only this code should fire. So i am sure this is not for the frontend but a backend implementation.

OR can i fire this javascript code on the

function fn_change_order_status($status_to, $status_from, $order_info, $force_notification = '', $order_statuses = '', $place_order = '') 
{
.....
}

But how to call javascript code here ?

OR can i fire this javascript code on the

function fn_change_order_status($status_to, $status_from, $order_info, $force_notification = '', $order_statuses = '', $place_order = '') 
{
.....
}

But how to call javascript code here ?

You cannot run javascript code here. If order status is changed from admin panel, you will received that the engage is undefined object. Search for alternative solution

The status details on the admin orders.details page will be updated when the status change ajax request returns. You can use a jquery event on the value of the select as a 'change' event to then look at that value and decide whether to execute your JS or not based on the value. It's a little convoluted. Check with your provider and see if they have a backend API that you can use to update from status change in php. You can then use the change_order_status hook.

I used a REST API instead of the JS Code. It works fine now.

I find that while JS is convenient for merchants to use because they can generally easily correlate a UI display with functionality, using a server-based solution (like a REST API) is usually much more efficient and much easier to apply business logic to. It also better fits a 3-tier model in that business logic remains on the server and is not embedded in the UI.