Forked from codearachnid/wc_customer_bought_product.php
Created
September 28, 2016 22:54
-
-
Save fufales/7a99326e5b7dd48b3cc1ba68f8af68c6 to your computer and use it in GitHub Desktop.
WooCommerce check if user has already bought product.
This file contains 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.' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment