# Stores/order Hooks not Working

**URL:** <https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807>\
**Category:** Ask the community\
**Tags:** code, wix-stores, question\
**Created:** [March 15, 2019, 6:30pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807 "2019-03-15T18:30:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcampos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jcampos/32/10121_2.png) [@jcampos](https://forum.wixstudio.com/u/jcampos)\
**Post date:** [March 15, 2019, 6:30pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/1 "2019-03-15T18:30:21Z")

</div>

Stores/order Hooks are not Working. We need it to get the orders and send it to another server integration…

Any one ?

---

<div class="post-metadata">

**Author:** ![hemisphere81](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hemisphere81/32/10458_2.png) [@hemisphere81](https://forum.wixstudio.com/u/hemisphere81)\
**Post date:** [March 25, 2019, 5:22pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/2 "2019-03-25T17:22:06Z")

</div>

It is Stores/Orders (S at the end). But I guess that doesn’t solve your problem? I’m having the same issue…

---

<div class="post-metadata">

**Author:** ![adas-bradauskas](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adas-bradauskas/32/669_2.png) [@adas-bradauskas](https://forum.wixstudio.com/u/adas-bradauskas)\
**Post date:** [April 18, 2019, 3:06pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/3 "2019-04-18T15:06:03Z")

</div>

Hey jcampos,

Unfortunately, you encountered a bug with Hooks functionality. We unintentionally exposed this option for Stores, but we currently don’t support it.

What might really help you is [onNewOrder()](https://www.wix.com/corvid/reference/wix-stores-backend.Events.html#onNewOrder) . Mind that this event should be added to your backend file.

---

<div class="post-metadata">

**Author:** ![hemisphere81](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hemisphere81/32/10458_2.png) [@hemisphere81](https://forum.wixstudio.com/u/hemisphere81)\
**Post date:** [April 18, 2019, 3:34pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/4 "2019-04-18T15:34:18Z")

</div>

Hey @adas-bradauskas , thans for clarifying! But when I look on onNewOrder() doc :  
[https://www.wix.com/corvid/reference/wix-stores-backend.Events.html#onNewOrder](https://www.wix.com/corvid/reference/wix-stores-backend.Events.html#onNewOrder)  
I don’t see WHAT was bought. How can we retrieve the product info like SKU-code?

---

<div class="post-metadata">

**Author:** ![jcampos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jcampos/32/10121_2.png) [@jcampos](https://forum.wixstudio.com/u/jcampos)\
**Post date:** [April 18, 2019, 9:30pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/5 "2019-04-18T21:30:37Z")

</div>

Hey Adas,

I placed the following code in the _ **event.js** _ in the _ **backend** _ . The _ **backEndLog** __ **collection** _ is to check if the onNewOrder(event) is working, but it is not working…it should insert a record at the backEndlog Collection when an event on wix-stores occurs…

[//event.js](https://event.js) code  
**import** wixData **from** ‘wix-data’;

**import** wixStores **from** ‘wix-stores-backend’;

export function wixStores\_onNewOrder(event) {

console.log(“New Order”);  
**let** newOrderId = event.orderId;  
**let** totalPrice = event.totals.total;

**let** toInsert = {  
“title”: “newOrderEvent.”,  
“order”: event  
};

wixData.insert(“backEndLog”, toInsert)  
.then( (results) =\> {  
**let** item = results; //see item below

console.log(‘item’+ JSON.stringify(item));  
} )  
. **catch** ( (err) =\> {  
**let** errorMsg = err;  
} );

}

export function wixStores\_onCartCreated(event) {  
**let** total = event.totals.total;

**let** toInsert = {  
“title”: “onCartCreated.”,  
“order”: event  
};

wixData.insert(“backEndLog”, toInsert)  
.then( (results) =\> {  
**let** item = results; //see item below

console.log(‘item’+ JSON.stringify(item));  
} )  
. **catch** ( (err) =\> {  
**let** errorMsg = err;  
} );  
}

export function wixStores\_onCartCompleted(event) {  
**let** total = event.totals.total;

**let** toInsert = {  
“title”: “onCartCompleted.”,  
“order”: event  
};

wixData.insert(“backEndLog”, toInsert)  
.then( (results) =\> {  
**let** item = results; //see item below

console.log(‘item’+ JSON.stringify(item));  
} )  
. **catch** ( (err) =\> {  
**let** errorMsg = err;  
} );

}  
As you can see not record was inserted on none of the events above…

 ![](https://us1.discourse-cdn.com/wix/original/3X/3/3/33cc0a68a41117157a9bcc899871cc3a01d990bc.png)  
Can you help?

---

<div class="post-metadata">

**Author:** ![adas-bradauskas](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adas-bradauskas/32/669_2.png) [@adas-bradauskas](https://forum.wixstudio.com/u/adas-bradauskas)\
**Post date:** [April 19, 2019, 7:00am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/6 "2019-04-19T07:00:44Z")

</div>

Hey Tom,

From _onNewOrder()_ you should get _orderId_ :

```javascript
export function wixStores_onNewOrder(event) {
  let newOrderId = event.orderId;
}

```

With this orderId, you should query Stores/Orders. There, you’ll find the items purchased.

---

<div class="post-metadata">

**Author:** ![adas-bradauskas](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adas-bradauskas/32/669_2.png) [@adas-bradauskas](https://forum.wixstudio.com/u/adas-bradauskas)\
**Post date:** [April 19, 2019, 7:19am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/7 "2019-04-19T07:19:35Z")

</div>

Are you running this code in Preview? What does the Sandbox database look like? You’re now showing us the Live version of it.

---

<div class="post-metadata">

**Author:** ![jcampos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jcampos/32/10121_2.png) [@jcampos](https://forum.wixstudio.com/u/jcampos)\
**Post date:** [April 19, 2019, 11:42am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/8 "2019-04-19T11:42:21Z")

</div>

The Sandbox database look the same

 ![](https://us1.discourse-cdn.com/wix/original/3X/a/2/a2a70a11d359975b602578d7d1342e3cb1aec54c.png)  
Do you have a working wix site sample we can take a look ?

If this works, then we must be doing something wrong or missing some directive…

---

<div class="post-metadata">

**Author:** ![jcampos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jcampos/32/10121_2.png) [@jcampos](https://forum.wixstudio.com/u/jcampos)\
**Post date:** [April 19, 2019, 11:48am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/9 "2019-04-19T11:48:55Z")

</div>

Hey Tom…did you get it to work ?

---

<div class="post-metadata">

**Author:** ![jcampos](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jcampos/32/10121_2.png) [@jcampos](https://forum.wixstudio.com/u/jcampos)\
**Post date:** [April 19, 2019, 2:38pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/10 "2019-04-19T14:38:52Z")

</div>

Hey Tom…did you get it to work ?

---

<div class="post-metadata">

**Author:** ![johnsonsflorists](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/johnsonsflorists/32/11026_2.png) [@johnsonsflorists](https://forum.wixstudio.com/u/johnsonsflorists)\
**Post date:** [May 2, 2019, 1:59am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/11 "2019-05-02T01:59:51Z")

</div>

Hi @jcampos , did you ever get this working. I don’t see my event ever get fired.  
Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![yucheng](https://avatars.discourse-cdn.com/v4/letter/y/eada6e/32.png) [@yucheng](https://forum.wixstudio.com/u/yucheng)\
**Post date:** [May 2, 2019, 2:43pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/12 "2019-05-02T14:43:53Z")

</div>

Hi @adas-bradauskas , have you ever got onNewOrder() working? It seems not be triggered on my site. Could you please provide some instructions to show how you did it? Thank you so much!

---

<div class="post-metadata">

**Author:** ![johnsonsflorists](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/johnsonsflorists/32/11026_2.png) [@johnsonsflorists](https://forum.wixstudio.com/u/johnsonsflorists)\
**Post date:** [May 7, 2019, 10:19pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/13 "2019-05-07T22:19:55Z")

</div>

Hi @adas-bradauskas , Can you give us an example of backend events.js working?  
Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![oduroagency](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/oduroagency/32/11502_2.png) [@oduroagency](https://forum.wixstudio.com/u/oduroagency)\
**Post date:** [May 8, 2019, 12:14am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/14 "2019-05-08T00:14:30Z")

</div>

Hello @adas-bradauskas , I also need instructions about events trigger…

---

<div class="post-metadata">

**Author:** ![adas-bradauskas](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adas-bradauskas/32/669_2.png) [@adas-bradauskas](https://forum.wixstudio.com/u/adas-bradauskas)\
**Post date:** [May 9, 2019, 7:06am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/15 "2019-05-09T07:06:26Z")

</div>

Tested it with this code in a published site:

```javascript
import wixData from 'wix-data';
import wixStores from 'wix-stores-backend';

export function wixStores_onNewOrder(event) {
 let newOrderId = event.orderId;
  wixData.insert('Logs', {'orders': newOrderId})
}

```

`orders` is a reference field in Logs collection, so it shows me the the order from Stores/Orders collection.

---

<div class="post-metadata">

**Author:** ![adas-bradauskas](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adas-bradauskas/32/669_2.png) [@adas-bradauskas](https://forum.wixstudio.com/u/adas-bradauskas)\
**Post date:** [May 9, 2019, 7:06am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/16 "2019-05-09T07:06:59Z")

</div>

Sure!

```javascript
import wixData from 'wix-data';
import wixStores from 'wix-stores-backend';

export function wixStores_onCartCreated(event) {
 let total = event.totals.total;
  wixData.insert('Logs', {'title': total})
}

export function wixStores_onNewOrder(event) {
 let newOrderId = event.orderId;
  wixData.insert('Logs', {'orders': newOrderId})
}

```

---

<div class="post-metadata">

**Author:** ![adas-bradauskas](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adas-bradauskas/32/669_2.png) [@adas-bradauskas](https://forum.wixstudio.com/u/adas-bradauskas)\
**Post date:** [May 9, 2019, 7:07am UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/17 "2019-05-09T07:07:49Z")

</div>

Check my answers above.

---

<div class="post-metadata">

**Author:** ![johnsonsflorists](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/johnsonsflorists/32/11026_2.png) [@johnsonsflorists](https://forum.wixstudio.com/u/johnsonsflorists)\
**Post date:** [May 9, 2019, 6:43pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/18 "2019-05-09T18:43:14Z")

</div>

@adas-bradauskas , Thanks Adas! Will try this. Also is that ‘title’ a typo? Shouldn’t it be something like ‘total’  
Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![johnsonsflorists](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/johnsonsflorists/32/11026_2.png) [@johnsonsflorists](https://forum.wixstudio.com/u/johnsonsflorists)\
**Post date:** [May 9, 2019, 7:01pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/19 "2019-05-09T19:01:52Z")

</div>

@adas-bradauskas , So I put in the above code in events.js file in backend section. I changed collection name to CartInfo, which I created already and have permissions set for everyone? Am I missing something. It just doesn’t seem to work on my site. I think either permission thing or something else possible? I was also able to insert into this table from other areas of site like front end I tested to make sure I can atleast do inserts like below and worked fine. Please Advise.

**import** wixData **from** ‘wix-data’;  
**import** wixStores **from** ‘wix-stores-backend’;

export function wixStores\_onCartCreated(event) {  
**let** total = event.totals.total;  
wixData.insert(‘CartInfo’, {‘total’: total})  
}

export function wixStores\_onNewOrder(event) {  
**let** newOrderId = event.orderId;  
wixData.insert(‘CartInfo’, {‘orderid’: newOrderId})  
}

---

<div class="post-metadata">

**Author:** ![johnsonsflorists](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/johnsonsflorists/32/11026_2.png) [@johnsonsflorists](https://forum.wixstudio.com/u/johnsonsflorists)\
**Post date:** [May 9, 2019, 7:25pm UTC](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807/20 "2019-05-09T19:25:16Z")

</div>

@adas-bradauskas , So I think I figured out what is going on, I guess this only works in live period, Even the on cart created, which you can do in preview but won’t work because this feature only seems to work in live. I thought I was sync my table every time, but just realized it was just going one way. So maybe I was over writing live every time? Not sure but if you switch to live on collection, then I can see data being added.  
Thanks,  
Tom

[Next page](https://forum.wixstudio.com/t/stores-order-hooks-not-working/15807.md?page=2)
