Menu Close

WooCommerce: Check if User Has Already Purchased Product

You can place PHP snippets at the bottom of your child theme functions.php file (before “?>” if you have it).

add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_user_logged_in_product_already_bought', 30 );functionbbloomer_user_logged_in_product_already_bought() {global$product;if( ! is_user_logged_in() ) return;$current_user= wp_get_current_user();if( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->get_id() ) ) echo'<div class="user-bought">&hearts; Hey '. $current_user->first_name . ', you\'ve purchased this in the past. Buy again?</div>';}