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 🙂
PHP Snippet: Show Product Published Date @ WooCommerce Single Product Page
/*
* @snippet WooCommerce: Show Product Published Date
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 5
* @community https://businessbloomer.com/club/
*/
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
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 🙂