Support

Account

Home Forums Front-end Issues Date front end display format

Helping

Date front end display format

  • I’m struggling to convert an ACF date picker field to be displayed in the correct format on the front end.

    I’m using this snippet to display the 2 product custom fields on the order confirmation and the associated email.

    add_action( 'woocommerce_order_item_meta_start', 'order_item_meta_start', 10, 4 );
    function order_item_meta_start($item_id, $item, $order, $plain_text) {
    	$the_order_id = $order->get_id();
    	$order_items = $order->get_items();
    	$custom_field_variable1 = get_post_meta( $item->get_product_id(), 'competition_reference', true ); // Change custom_field_name to the name of your custom product meta field
    	$custom_field_variable2 = get_post_meta( $item->get_product_id(), 'competition_draw_date', true ); // Change custom_field_name to the name of your custom product meta field
    	echo '<p>Competition Reference: ' . $custom_field_variable1 . '<br>Competition Draw Date: ' . $custom_field_variable2 . '</p>';
    }

    It works in the fact it displayed the ACF data, but it displays the date as YYYYMMDD rather than my ACF return format of dd/mm/YYYY

    Product
    LEGO® Star Wars™ Darth Vader Helmet (75304)
    Competition Reference: LegoDV_001
    Competition Draw Date: 20230630

    How can I return the date correctly?

  • ACF only formats the value of the date field when you use an ACF function to get the value of that field. ACF stores date fields as “Ymd” format regardless of the return format that you have set.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.