Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fufales/7a99326e5b7dd48b3cc1ba68f8af68c6 to your computer and use it in GitHub Desktop.
Save fufales/7a99326e5b7dd48b3cc1ba68f8af68c6 to your computer and use it in GitHub Desktop.
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.' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment