WooCommerce: Get & Return All Product IDs

When you work with WooCommerce PHP snippets, you often need to “get” stuff off your WooCommerce database in order to make some calculations and return the result on the screen. And if there is something I often google is “How do I get all my store’s product IDs?“.

Thankfully the get_posts WordPress function gives us the answer. In the next weeks we’ll also see how we can get other information, such as all SKUs, all product categories, etc.

So, here’s the quick snippet to return all product IDs on the Cart page (“woocommerce_before_cart” hook) – you can change that if you want to use them somewhere else. Enjoy ๐Ÿ™‚

Continue reading WooCommerce: Get & Return All Product IDs

WooCommerce: Check if Product ID is in the Order

Once a customer places an order, you might want to know if such order contains a given product ID. you can use this for tracking purposes, redirect to a custom thank you page or run your custom functions.

Either way, checking this is quite simple thanks to the “woocommerce_thankyou” hook which runs on the order received page. Enjoy!

Continue reading WooCommerce: Check if Product ID is in the Order