1. Knowledge Base
  2. WooCommerce Product Table
  3. Advanced Usage

Adding a ‘Date Modified’ column to the product table

The WooCommerce Product Table WordPress plugin lists your products in a table or one-page order form. You can choose which columns to include, including a date column containing the date when the post was published. While it doesn’t come with a ‘Date modified’ column, we have provided a code snippet which will add a column containing the date when the product was last updated.

WordPress posts display modified date
A product table with a custom 'Last Updated' column.

Please note that this code is aimed at developers and if you don’t know how to use it, then we recommend posting a job on Codeable. We have partnered with Codeable to provide customizations for our plugins.

Need professional assistance?
We've partnered with Codeable to provide our customers with expert help if required.

1. First, add modified_date to your list of columns

Once you have installed WooCommerce Product Table, you need to include modified_date in the list of columns.

For example, if you are setting the columns directly in the shortcode (instead of on the plugin settings page) then you might add:

[[product_table columns="image,name,modified_date,add-to-cart"]]

The column header will say ‘Modified date’. You can easily change this using these instructions.

2. Use code snippet to add a custom column

Next, you need to use the following code snippet to create a custom column containing the product last modified date:

/**
 * Gets data for the 'modified_date' column to use in the product table.
 *
 * @license   GPL-3.0
 */
if ( class_exists( 'Abstract_Product_Table_Data' ) ) {
    class Product_Table_Data_Modified_Date extends Abstract_Product_Table_Data {
        //Get date_format value from the shortcode if it exists
        public function __construct( $product, $date_format = 'F j, Y' ) {
            parent::__construct( $product );
            $this->date_format = $date_format;
        }

        public function get_data() {
            // Retrieve the modified date.
            $data = $this->product->get_date_modified()->date($this->date_format);

            // Return the modified date and run through a filter.
            return apply_filters( 'wc_product_table_data_modified_date', $data, $this->product );
        }
    }

    add_filter( 'wc_product_table_custom_table_data_modified_date', function( $data_obj, $product, $args ) { 
        return new Product_Table_Data_Modified_Date( $product, $args->date_format ); 
    }, 10, 3 );
}

This code snippet can be added to your theme’s functions.php file or you can add it to a custom plugin.

Again, if you don’t know how to use the code snippet then you should ask your developer or Codeable:

Need professional assistance?
We've partnered with Codeable to provide our customers with expert help if required.
Still need help?
If searching the knowledge base hasn't answered your question, please contact support.

Related Articles