title: Undefined variable $product_id in Woocommerce hooked function
body: <p>I know there is another question similar, but my problem look strange. I am running a PHP script, and keep getting errors like:</p>
  
  <blockquote>
    <p>Notice: Undefined variable: product_id in D:\  MY-WEBSERVER\InstantWP_4.3.1\iwpserver\htdocs\wordpress\wp-content\themes\MYTHEME\functions.php on line 580</p>
  </blockquote>
  
  <p>Line 580 looks like this:</p>
  
  <pre><code> if ( wc_customer_bought_product( $current_user-&gt;user_email, $current_user-&gt;ID, $product_id ) ) echo '&lt;div class="user-bought"&gt;&amp;hearts; Hey ' . $current_user-&gt;first_name . ', you\'ve purchased this in the past. Buy again?&lt;/div&gt;';
  </code></pre>
  
  <p>Here full code:</p>
  
  <pre><code> add_action ( 'woocommerce_after_shop_loop_item', 
   'user_logged_in_product_already_bought', 30);
  
   function user_logged_in_product_already_bought() {
   if ( is_user_logged_in() ) {
   global $product;
   $current_user = wp_get_current_user();
   if ( wc_customer_bought_product( $current_user-&gt;user_email, $current_user-&gt;ID, $product_id ) ) echo '&lt;div class="user-bought"&gt;&amp;hearts; Hey ' . $current_user-&gt;first_name . ', you\'ve purchased this in the past. Buy again?
   &lt;/div&gt;';
   }
   }
   ?&gt;
  </code></pre>
  
  <p>Is there a quick fix to resolve these notify?
  Really appreciate for any help</p>
  
  <p>Thank you</p>