Hello WooCommerce Customizers! Today we take a look at the WooCommerce Single Product Page and specifically at how to display the product/post published date. It might be useful to users in case you need to show how “new” a product is, or if you have specific needs. Enjoy ๐
WooCommerce: Show Product Published Date
PHP Snippet: Show Product Published Date @ WooCommerce Single Product Page
/*
* @snippet WooCommerce: Show Product Published Date
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 5
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_action(
'woocommerce_single_product_summary', 'bloomer_echo_product_date', 25 );
function bloomer_echo_product_date() {
if ( is_product() ) {
echo the_date( '', '<span class="date_published">Published on: ', '</span>', false );
}
}
// Change the date format: https://codex.wordpress.org/Function_Reference/the_date
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
Hello Rudolfo. Thanks for that awesome snippet of code. I was curious if it is possible to show on shop everywhere, you know what I mean, shop-page, category pages. Would need to show Date Added in those Product Columns hmm. Thanks very much, you are the man!
Hi Michal, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It’s not the same, but related. Do you know how to export the published date?
So far I’ve been able to add other elements to the exporting CSV that comes bundled in WC, like the slug, but with the date, nothing so far.
Your help is appreciated, thanks!
Hey Santiago, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hello, I sell one of a kind products! I would like to show the month/year it was sold when a visitor sees the product page …any code to help me with this please??
Hello James, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hey there, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Mabi, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Sorry Marian, I thought I replied to this comment already. Of course there is – but I’m afraid I cannot provide support here via the blog comments ๐ Thanks for your understanding. R
How would I use this to get the product publish date when trying to calculate selling time to be stored to order items meta data? I’m using wc_add_order_item_meta function and hook to store the information of for the order items but don’t know how to get the date easily. Any ideas?
Hey Juhani, thanks for your comment! Your request is a little off topic… but here’s what I’d do: when you open any order within WooCommerce admin, you will see date and time. Somewhere in the WooCommerce code, there is a function that is saving that timestamp already – all you need to do is to “get” it via PHP and echo the value on emails or pages. Hope this helps!
Questions? Feedback? Support? Leave your Comment Now! _____
If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)
With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.
Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.
Thanks for your great article, I’d like to ask, is there any way to get the ” product’s last modified time ” by product ID?
Hi Reza, yes! https://www.businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/
This is great. Is it possible to move this below the button?
Cool! Try increasing the priority (which is 25 at the moment)
Hello Rudolfo. Thanks for that awesome snippet of code. I was curious if it is possible to show on shop everywhere, you know what I mean, shop-page, category pages. Would need to show Date Added in those Product Columns hmm. Thanks very much, you are the man!
Hi Michal, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It worked perfectly even today, thanks.
Awesome!
Hi Rodolfo,
It’s not the same, but related. Do you know how to export the published date?
So far I’ve been able to add other elements to the exporting CSV that comes bundled in WC, like the slug, but with the date, nothing so far.
Your help is appreciated, thanks!
Hey Santiago, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hello, I sell one of a kind products! I would like to show the month/year it was sold when a visitor sees the product page …any code to help me with this please??
Hello James, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
how to show woocommerce product publish time on shop page. I am using vantage and Di blog themes.
Hey there, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Hi Rodolfo
cool snippet. Is it possible to show it on a product attribute?
thx, bye
Mabi, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R
Is there a way to change the functionality so that is will show the last updated date instead?
Thank you.
Sorry Marian, I thought I replied to this comment already. Of course there is – but I’m afraid I cannot provide support here via the blog comments ๐ Thanks for your understanding. R
how to display date in shop page also. this one displays date on product page but what about product list page or shop page.
Hey Sachin thanks for your comment! You could try using another hook (reference: https://businessbloomer.com/woocommerce-visual-hook-guide-archiveshopcat-page/) in order to make it show on the shop page. Hope this helps ๐
How would I use this to get the product publish date when trying to calculate selling time to be stored to order items meta data? I’m using wc_add_order_item_meta function and hook to store the information of for the order items but don’t know how to get the date easily. Any ideas?
Hey Juhani, thanks for your comment! Your request is a little off topic… but here’s what I’d do: when you open any order within WooCommerce admin, you will see date and time. Somewhere in the WooCommerce code, there is a function that is saving that timestamp already – all you need to do is to “get” it via PHP and echo the value on emails or pages. Hope this helps!
cool
Thank you Zoran ๐