Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

Check If User Already Purchased Product

If a given logged in user had already purchased a certain product ID. It will show special notices on the shop or single product page to motivate customers to buy the same item again.

So, here is code. which you can add in your theme’s functions.php file of your active child theme (or theme).


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->user_email, $current_user->ID, $product->get_id() ) ) echo '
♥ Hey ' . $current_user->first_name . ', you\'ve purchased this in the past. Buy again?
'; } }
Exit mobile version