Created
February 27, 2014 21:07
-
-
Save codearachnid/9259601 to your computer and use it in GitHub Desktop.
WooCommerce check if user has already bought product.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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.' ); | |
} |
Hi man, how can i do this, but for specific product ID?
Perfect. Thank you very much.
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
It's been a long time since you uploaded this, but I need to ask, after we create this file in woocommerce -> includes, how do we check if a product it purchased or not? Thanks.