Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am currently building a Theme for a site that is using WooCommerce to provide a shop to Customers. I have just started on it, and I am currently working on the Product Category pages. I have hit a road block trying to fetch the Product object.

I have read that using the variable global $product should return the WC_Project object, but when I do the_post(); var_dump($product), NULL is returned.

I tried to then create a Product object by doing the_post(); $product = new WC_Product(get_the_ID()), but when I did the var_dump($product) on that, it gave me general information about the product (post_name, post_description, etc), but nothing further than if I called get_post().

Can someone tell me what I have missed please?

share|improve this question
add comment

1 Answer

Sorry, I have almost instantly found the solution. Thought about deleting the question, but in case others have the same problem, I will leave it here.

To get the Product object with all the required attributes, you need to call get_product() after the_post(), and that will return the Product object for you to use.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.