I want to display on a page if the logged in user has ordered a specific product.
I can't find a function in WC_Order that would allow me to get this information.
CodePudding user response:
If you want to check the user has already bought a product then you can use the wc_customer_bought_product function to check that (documentation reference)
The code will look like this:
wc_customer_bought_product('', get_current_user_id(), $product->get_id())
CodePudding user response:
Full code will look something like this
if(wc_customer_bought_product(get_current_user_id(), PRODUCT ID)){
//the customer has bought specified product
} else {
//the customer has not bought specified product
}