• Resolved sophiekroezen

    (@sophiekroezen)


    Hello,

    The current date format for the invoice is ‘December 12, 2020′. I would like to change this to the Dutch date format. Preferably, I would like ’12 December 2020’. But the plugin doesn’t recognise Dutch month names.

    Therefore I put the following code in invoice.php:

    <tr class="order-date">
    					<th><?php _e( 'Order Date:', 'woocommerce-pdf-invoices-packing-slips' ); ?></th>
    					<?php setlocale(LC_ALL,'nl_NL'); ?>
    					<td><?php echo date("d/m/Y") ?></td>
    				</tr>

    It resulted in the date format 12/12/2020. However, after a recent update this code doesn’t work anymore.

    Is it possible to set the date format in the settings of the plugin? Or to make this setting available? Or can someone help me with correct code tot put in invoice.php?

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hello Sophie,
    The date format for the invoice is taken from WooCommerce (wc_date_format), which in turn is taken from the WordPress date format (Settings > General > Date Format).

    The easiest way to change the date format on the invoice is to change that general setting, but obviously that will also change the date format in your site. The language of that date will automatically follow your own language settings.

    If you want to change the date format that WooCommerce uses you can do that with the following filter:

    
    add_filter( 'woocommerce_date_format', 'woocommerce_custom_date_format' );
    function woocommerce_custom_date_format( $date_format ) {
    	return 'd/m/Y';
    }
    

    Or if you want to change the date format only for the invoice you can use the following filter:

    
    add_filter( 'wpo_wcpdf_date_format', 'wcpdf_custom_date_format' );
    function wcpdf_custom_date_format( $date_format ) {
    	return 'd/m/Y';
    }
    

    This way you don’t need to modify the template (also noting that the usage of date() will always show the date the document is opened rather than when it was first generated).

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

Viewing 1 replies (of 1 total)
  • The topic ‘Change Date Format’ is closed to new replies.