title: socket.io - send notification to admin when order place in WooCommerce
body: <p>I have create script for Nodejs server working properly. Connect with contact form 7 when contact request send admin get notification and notification counter get updated. I have same logic implement for WooCommerce thank you page when order place send notification. Its not working there.</p>
  <ul>
  <li>send notification to admin when WooCommerce order received</li>
  <li>is it possible to get notification for different site?</li>
  </ul>
  <p><strong>Code Woocoomerce</strong></p>
  <p>script.js when thank you page load</p>
  <pre><code>jQuery( document ).ready(function() {
   var socketIO = io(&quot;http://localhost:3000&quot;);
  
   var userId = 10;
   socketIO.emit(&quot;connected&quot;, userId);
   socketIO.emit(&quot;newNotification&quot;, userId);
   // console.log(&quot;Emit executed&quot;);
  });
  </code></pre>
  <p>admin-script.js its in admin</p>
  <pre><code> // connect with Node JS server
   var socketIO = io(&quot;http://localhost:3000&quot;);
   
   // connect user with Node JS server
   var userId = 10;
   socketIO.emit(&quot;connected&quot;, userId);
  
  
   // when a new notification is received
   socketIO.on(&quot;newNotification&quot;, function (data) {
       var counter = jQuery('span.notificationcounter').val() + data;
      jQuery('span.notificationcounter').val(counter );
   });
  </code></pre>
  <p><strong>NodeJS server Code</strong></p>
  <pre><code>// initialize express server
  var express = require(&quot;express&quot;);
  var app = express();
   
  // create http server from express instance
  var http = require(&quot;http&quot;).createServer(app);
   
  // include socket IO
  var socketIO = require(&quot;socket.io&quot;)(http, {
      allowEIO3: true,
      cors: {
          origin: [&quot;http://localhost&quot;]
      }
  });
  
  app.get('/', function(req, res){
      res.render(&quot;Vasim Shaik&quot;);
    });
  
  // start the HTTP server at port 3000
  http.listen(process.env.PORT || 3000, function () {
      // console.log(&quot;Server started running...&quot;);
   
      // an array to save all connected users IDs
      var users = [];
   
      // called when the io() is called from client
      socketIO.on(&quot;connection&quot;, function (socket) {
          
          // called manually from client to connect the user with server
          socket.on(&quot;connected&quot;, function (id) {
  
              users[id] = socket.id;
              socketIO.to(users[id]).emit(&quot;connected&quot;, id);
  
              
          });
          // when a new notification is received
          socket.on(&quot;newNotification&quot;, function (userId) {
           
              // send notification to the selected user
              socketIO.to(users[userId]).emit(&quot;newNotification&quot;, {message:&quot;new contact request&quot;,count:1});
  
          });
  
          // when a new notification is received
          socket.on(&quot;readNotification&quot;, function (userId) {
           
              // send notification to the selected user
              socketIO.to(users[userId]).emit(&quot;readNotification&quot;, userId);
          });
      });
  });
  </code></pre>
  <p><strong>Implemented Code - Updated answer :</strong></p>
  <p><a href="https://i.stack.imgur.com/yHPcF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yHPcF.png" alt="enter image description here" /></a></p>
  <p>In admin script in WordPress :</p>
  <p><a href="https://i.stack.imgur.com/D4BLd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D4BLd.png" alt="enter image description here" /></a></p>
  <p>In Express server :
  <a href="https://i.stack.imgur.com/R064f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R064f.png" alt="enter image description here" /></a></p>