Add Published Date Per Product – WooCommerce

This code enables you to add the date your product was published in any WordPress theme. The code includes :

  • Schema markup
  • ACF .json file to show or hide the product date
  • A special function for human time difference
  • A function for the date which includes parameters for before, after, label and time format.
  • A function to output the date on single product pages if your custom field value is set to true (1).

Example output in HTML source :

<time class="product-date" itemprop="datePublished" datetime="2022-05-28T07:06:38+00:00">May 28, 2022</time>

To do this, you need to setup a input method and use PHP code for the output.

Input

You have 2 ways to input your custom field value for true or false :

(1) You can show the date using this ACF .json file which products this switch added to the Edit Product screen

(2) or use a WordPress custom field named product_date using a value of 1 for true and 0 for false.

Tested using the Twenty Twenty default theme for WordPress & Genesis.

Installation – Output

There’s only 1 step :

Copy & paste the PHP code from the download folder to the end of your child themes functions file.

Download Folder

Genesis Users

Note : The code is written to work with non Genesis themes. If using Genesis, change this line of the PHP code from :

echo woocommerce_product_date();

to :

echo do_shortcode('[[post_date]]');

You do NOT need to use the genesis_human_time_diff and woocommerce_product_date product functions if using Genesis. Only use the add_product_date function with the modified output for the post_date as stated above if using any Genesis child theme.

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.