How to Get WooCommerce Product ID
In WooCommerce, a product ID is a unique figure that is assigned to every product in your online store. As soon as a WooCommerce product is created, WordPress automatically produces an ID for the particular product. Products are treated as custom post types(CPTs) by WordPress, so, consequently, WordPress stores any corresponding information within their database and labels it accordingly. Let us take a look at different methods to how can the WooCommerce product ID be found.
WooCommerce Product ID via URL
One of the simplest methods for finding the product ID is via the WordPress dashboard. Start with locating the Products tab, just underneath WooCommerce.
Choose any product you like and click on it. You will be re-directed to the Edit Product page. Now, take a look at the URL that has been displayed. It should look similar to this:
Right after the keyword post, you will see a number. This number is the product ID that you have been looking for. In the example above it is 46.
WooCommerce Product ID via Dashboard
You might think that the aforementioned method is the easiest out there, but, in reality, there is a more straightforward way of finding the WooCommerce product ID. Go back to the main Products tab and just hover over any product. Right next to the Edit button, you will see the product ID displayed in a grey color.
If you are savvy with coding and databases in general, then you can find the product id via the SQL command centre. Login to your phpMyAdmin account. Before proceeding, confirm that the script will be run on the correct database. To ratify whether the correct database is loaded, look for the table wp_options and check if it has the correct URL for your website. Always backup your website before running any script! Otherwise, you may lose significant data or even render the website inaccessible. You should regularly take precautions when running advanced SQL queries.
In the SQL command panel, post the following code snippet. If your database prefix is not wp_, then replace it with the prefix you are using. Press the Go button to execute the SQL statement.
SELECT post_id FROM wp_postmeta WHERE meta_key='_sku' AND meta_value='sku-name';
With this SQL query, any product with an SKU will return its WooCommerce product ID.
As you can see, finding the WooCommerce product ID is rather straightforward. By applying one of the aforementioned methods, you are sure to find the right ID instantaneously. We wish you a safe journey through the world of web development, stay tuned for more articles!
KEEP YOUR ONLINE SHOP SAFE WooCommerce Maintenance Service
Save 17% with our Annual pricing plan.