-1

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.

Kzou
  • 1
  • 1

2 Answers2

0

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())
DarkBee
  • 16,592
  • 6
  • 46
  • 58
Vijay Hardaha
  • 2,411
  • 1
  • 7
  • 16
0

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

}
Coopero
  • 296
  • 2
  • 10