如何让WooCommerce格式的订单日期本地化为西班牙语?



我看到以下代码显示WooCommerce订单的完成日期

echo 'Fecha: '. $order->get_date_completed()->format ('j F, Y').'<br>';

但我希望显示器的格式为西班牙语。 如何让此日期格式化为西班牙语,例如我的网站?

使用WC_Datetimedate_i18n() method显示本地化的格式化日期,如下所示:

// Only for completed orders 
if( $date_completed = $order->get_date_completed() ){
// Display the localized formatted date
echo "Fecha: " . $date_completed->date_i18n('j F, Y') . "<br>";
}

它应该有效。

另请参阅:WordPress文档date_i18n()

最新更新