• Resolved WebDynamix

    (@dzinefactory)


    Hi There

    I’m looking for a way to format a custom date field within a packing slip template. The code I’m using is below, and is straight from the plugin documentation:

    $this->custom_field(‘_fulfilment_date’);

    The above displays the date with no formatting. I have modified the code to below – as well as several version of this – to try and format it correctly, but this then displays the unformatted date right before the formatted date.

    $date = $this->custom_field(‘_fulfilment_date’);
    $formatted_date = date(‘d M Y’, strtotime($date));
    echo $formatted_date;

    Any help with how to achieve what I’m after would be much appreciated!

    • This topic was modified 2 years, 10 months ago by WebDynamix.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @dzinefactory,

    We follow the WordPress date format for the dates displayed on the PDF documents. However, you can customize them using the wpo_wcpdf_date_format filter hook, like this:

    /**
     * PDF Invoices & Packing Slips for WooCommerce:
     * Customize the date format on the PDF documents
     */
    add_filter( 'wpo_wcpdf_date_format', function( $date_format, $document, $date_type ) {
    	$date_format = 'm/d/Y'; // Set the date format here
    	return $date_format;
    }, 10, 3 );

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

    Thread Starter WebDynamix

    (@dzinefactory)

    Hi @yordansoares

    Thanks for your reply. Unfortunately this only seems to work for the date fields that are default on the Woo Checkout page. The date field I’m trying to format is a ‘delivery date’ field that is added via a third party plugin to the checkout page. The custom field is ‘_fulfilment_date’ and I have added it via this custom snippet – $this->custom_field(‘_fulfilment_date’); – as the plugin documentation says.

    The date output looks like this – 2023-07-31

    Any ideas how to format a custom date field?

    Thanks

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Thanks for providing more details, @dzinefactory.

    If you want to customize the date from a custom field, you can try to do the following:

    $fulfilment_date = date_i18n( 'm/d/Y', strtotime( $this->order->get_meta( '_fulfilment_date' ) ) );
    Thread Starter WebDynamix

    (@dzinefactory)

    Hi @yordansoares

    That worked perfectly.

    Thanks for your help! Much appreciated!

    • This reply was modified 2 years, 10 months ago by WebDynamix.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    I’m happy to hear that, @dzinefactory!

    If you don’t mind and have the time, do you think you could leave us a review?

    Thanks in advance and all the best with your store!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Custom Date Field’ is closed to new replies.