Undefined variable $product_id in Woocommerce hooked function

admin

Administrator
Staff member
I know there is another question similar, but my problem look strange. I am running a PHP script, and keep getting errors like:

<blockquote>
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
</blockquote>

Line 580 looks like this:

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;';

Here full code:

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;

Is there a quick fix to resolve these notify?
Really appreciate for any help

Thank you