skip to Main Content

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.

2

Answers


  1. 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())
    
    Login or Signup to reply.
  2. 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
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search