Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created February 27, 2014 21:07
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save codearachnid/9259601 to your computer and use it in GitHub Desktop.
Save codearachnid/9259601 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.' );
}
@fufales
Copy link

fufales commented Sep 29, 2016

Hi man, how can i do this, but for specific product ID?

@advancedsoftwarecanada
Copy link

Perfect. Thank you very much.

@aleksandrx
Copy link

Hi man, how can i do this, but for specific product ID?

$product = $wc_pf->get_product('123');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment