Shortcode: [expiry_date]
The [expiry_date] shortcode allows you to display the expiration details of a product anywhere on its page. It automatically detects the product it is placed on and shows the relevant date or custom note. You can use it in custom WooCommerce pages or Elementor.
Basic Usage
Simply paste the following code into your product description, a shortcode block, or a custom tab:
[expiry_date]
Customizing the Output
You can add your own text before or after the date using the before and after attributes. This is helpful for adding labels or small icons.
| Attribute | Description | Example |
before | Text or symbols to show before the date. | before="Expires on: " |
after | Text or symbols to show after the date. | after=" (Limited Stock)" |
Examples
1. Displaying a simple label
- Shortcode:
[expiry_date before="Best Before: "] - Result: Best Before: 12/31/2026
2. Adding a suffix
- Shortcode:
[expiry_date before="Use by " after=" for best quality."] - Result: Use by 05/15/2026 for best quality.
How it Works
- Automatic Detection: The shortcode only works on single product pages. If it’s used elsewhere, it will remain hidden.
- Custom Notes: If you have entered a Custom Expiry Note for a product, the shortcode will display that note instead of the standard date.
- Smart Hiding: If no expiry date is set for a product, the shortcode will return nothing, ensuring your layout stays clean.
Pro Tip: If you are using a page builder (like Elementor or Divi), you can place this shortcode inside a Text or Code widget within your product template.
