如何在多语言WooCommerce站点自定义date_i18n日期格式
d-m-Y in Your Multilingual Site Hey there! Let's sort out this date formatting problem you're facing. Right now, your code uses wc_date_format() which pulls the date format set in your WordPress/WooCommerce site settings—if that's configured to something like j F Y, you'll get the English month name output like "15 June 2018".
To get the exact 15-06-2018 format you want, you don't need to rely on wc_date_format() at all. Instead, you can pass the specific format string directly to date_i18n():
$expiry = date_i18n('d-m-Y', strtotime('+'.$expiry.' days'));
Let me break down what each part of the format string does:
d: Two-digit day (01 to 31)m: Two-digit month (01 to 12)Y: Four-digit year (e.g., 2018)
This will consistently output dates in the dd-mm-yyyy numeric format, regardless of your site's default date settings. And since you're still using date_i18n(), it will respect your site's timezone and any locale-specific numeric rules (though for this numeric format, it will look consistent across most languages).
As for your question about using something like wc_date_format(d, m, y)—unfortunately, the wc_date_format() function doesn't accept parameters. It only returns the date format string configured in your WooCommerce settings. So passing your desired format directly to date_i18n() is the correct approach here.
内容的提问来源于stack exchange,提问作者Elichy

