butlerblog
3/6/2016 - 3:20 AM

WooCommerce check if user has already bought product.

WooCommerce check if user has already bought product.

<?php

// if product is already in global space
global $product;

// or fetch product attributes by ID
if( empty( $product->id ) ){
	$wc_pf = new WC_Product_Factory();
	$product = $wc_pf->get_product($id);
}

// get user attributes
$current_user = wp_get_current_user();

// determine if customer has bought product
if( wc_customer_bought_product( $current_user->email, $current_user->ID, $product->id ) ){
	_e( 'Product already purchased.' );
}