How to set and display the WooCommerce product expiration date and time in WordPress

You might want to set and display the end date of a WooCommerce product in WordPress. WooCommerce "Product" posts are a kind of "custom post types." Therefore, it's possible to specify the expiration date for each product posts if you use a plugin which enables you to set the expiration date and time for a "custom post type." When the date and time is due, the affected post will be set to "Draft" or be moved to a specific category or will be deleted depending on the action specified by the user.

There are several paid-in or free plugins which support this feature. One of the me is a WordPress plugin named Post Expirator. After installing and activating this plugin, you can set details options by visiting "Settings" -> Post Expirator in the WordPress Dashboard,

Post Expirator Options in WordPress

After changing and saving the options, you can set the expiration date for a WooCommerce product page.

Set expiration date and time for a WooCommerce post using Post Expirator in WordPress

As shown above, if you want to set an end date and time for a specific WooCommerce product post, please check the option "Enable Post Expiration" and specify the expiration date and time. Under "How to expire:", you can specify how to process the post when the expiration date is due. If you choose "Draft," the affected product post will be moved to "Draft" when the product end date is due.

Now, let's display the expiration date in each product page. We need to modify a WooCommerce template file for this.

Post Expirator Options in WordPressDisplay Product End Date in WooCommerce

The file which needs to be modify is "short-description.php " under "/woocommerce/wp-content/plugins/woocommerce/templates/single-product" folder (which can be accessed via FTP.). The plugin "Post Expirator" supports a shortcode: "postexpirator." You can insert this shortcode in this file. For example, you can use the following code:

Postexpirator Shortcode in WordPress
If you want to display "No expiration date" for posts where you did not specify the expiration date, you can use a conditional tag.

Related Post:

Leave a Comment