You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在多语言WooCommerce站点自定义date_i18n日期格式

Fixing Date Format to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:11:56