Posted on

WooCommerce: Show Published Date @ Single Product

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
WooCommerce: Show Product Published Date

WooCommerce Snippet: Show Product Published Date


/**
 * @snippet       WooCommerce: Show Product Published Date
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=19936
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.4.2
 */

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

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

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.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

14 thoughts on “WooCommerce: Show Published Date @ Single Product

  1. 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??

    1. 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

  2. how to show woocommerce product publish time on shop page. I am using vantage and Di blog themes.

    1. 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

  3. Hi Rodolfo

    cool snippet. Is it possible to show it on a product attribute?

    thx, bye

    1. 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

  4. Is there a way to change the functionality so that is will show the last updated date instead?
    Thank you.

    1. 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

  5. how to display date in shop page also. this one displays date on product page but what about product list page or shop page.

    1. 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 ๐Ÿ™‚

  6. 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?

    1. 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!

    1. Thank you Zoran ๐Ÿ™‚

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.