Date format for custom Dynamic Field (Not ACF)

Hello there, I am trying to bring in a custom field produced by the Preorder Plugin for Woocommerce by Bright Plugins into a product page. I can access the field through the “Meta (Custom Field)” dynamic field, but what I get is an ugly 2021-04-01 00:00:00 returned and no way to format it. I’ve tried adding format="F j, Y" to the syntax, but it doesn’t seem to work. Is this date format feature only available on certain fields?

As an alternative, I’ve created this custom shortcode in my functions.php, but for some reason it doesn’t seem to be working. Any ideas why?

//This is a custom shortcode to return a formatted version of the Preorder date
function print_formatted_preorder_date() {
  $preorderdate = strtotime(get_post_meta($product->get_id(), '_pre_order_date', true));
  print date_format($preorderdate, 'F j, Y');
}
add_shortcode('preorder_date', 'print_formatted_preorder_date');

Hi @bobbybosler,

I would suggest using the date function instead of date_format. I have modified your code and added my code by replacing your one. Please find the following code.

function print_formatted_preorder_date() 
{
    $preorderdate = strtotime(get_post_meta($product->get_id(), '_pre_order_date', true));
    echo date('F j, Y', strtotime($preorderdate));
}
add_shortcode('preorder_date', 'print_formatted_preorder_date');

Hope it helps.
Thanks

@tristup,

Thank you for the help. The code still didn’t work, but I don’t expect you to do custom dev for me.

So, there’s no way to custom format a php date from a dynamic field?

Hello @bobbybosler,

Regretfully there isn’t an option that formats the data in the dynamic field.

By the way, the code should be added as [preorder_date ].

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.