title: Simple php code to count visitors on one page and display in footer
body: <p>I'm new, and learning.  I only have a single digital product.  I want to display the total number of purchases made, in my footer (on all pages).  I have not been able to find a lightweight plugin that can do this, nor any code that works.  I am using Woocommerce and since I only have a single product, buyers are taken directly to the checkout page once they click on &quot;Buy&quot;.  Once their payment goes through they are taken to a Thankyou page.  I thought that if I can count the number of visitors who visit this Thankyou page and display that, it would give a pretty accurate number of purchases.  I am able to do everything except that I do not know how to count the visitors on just that single page.  My page is id=376, but how could I call that?  Here is the php code that I'm trying.  I think I need to swap the fgets($file, 1000) with the actual page id???</p>
  <pre><code>$path = 'C:/xampp/apps/wordpress/htdocs/counter.txt';
  
  // Opens counter.txt to read the number of hits.
  $file  = fopen( $path, 'r' );
  $count = fgets( $file, 1000 );
  
  /*$count = fgets( $file, 1000 );*/
  fclose( $file );
  
  // Update the count.
  if ($page_id == 376) {
  $count = abs( intval( $count ) ) + 1;
  }
  // Output the updated count.
  echo &quot;This product has been purchased &lt;strong&gt;0000{$count}&lt;/strong&gt; times\n&quot;;
  
  // Opens counter.txt to change new hit number.
  $file = fopen( $path, 'w' );
  fwrite( $file, $count );
  fclose( $file );```
  </code></pre>