Problem: I would like to display the WooCommerce Order's completed date, but the hidden custom field _completed_date is not formatted as I would like.
Solution:
Add this custom shortcode to your functions.php file:
function format_completed_date_func($atts) { $a = shortcode_atts( array( 'format' => 'm d Y', 'orderid' => 0 ), $atts ); $completedDate = get_post_meta( $a['orderid'], '_completed_date', true ); if ( !$completedDate ) return; $time = strtotime($completedDate); $date = date($a['format'], $time); return $date; } add_shortcode( 'format_completed_date', 'format_completed_date_func');
Use the custom shortcode in a View's loop like this:
[format_completed_date format='m/d/Y' orderid='[wpv-post-id]']
Replace m/d/Y with the PHP date formatting of your choice.
Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta
https://codex.wordpress.org/Shortcode_API
http://php.net/manual/en/function.date.php
http://php.net/manual/en/function.strtotime.php
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 4 replies, has 2 voices.
Last updated by 6 years, 6 months ago.
Assisted by: Christian Cox.