【问题标题】:How can I get the order date, in WooCommerce?如何在 WooCommerce 中获取订单日期?
【发布时间】:2015-10-23 04:02:00
【问题描述】:

我可以看到class-wc-admin-cpt-shop_order.php 内部有一些功能将订单信息汇总在一起以在 WooCommerce 中显示。但是,我没有看到可以使用日期的任何地方...

因为 WooCommerce 使用 wp_posts 来存储数据,我可以假设 post_date field 是正确的使用吗?

此外,任何人都知道 WooCommerce 中是否有获取此功能的功能,或者是否有办法在 class-wc-admin-cpt-shop_order.php 中获取日期。

【问题讨论】:

  • 嗨,d74p,您建议的以“因为”而不是“因为”开头的句子在语法上不正确。

标签: wordpress woocommerce


【解决方案1】:
// Get $order object from order ID 
$order = wc_get_order( $order_id );

// Get Order Dates
$order->get_date_created();
$order->get_date_modified();
$order->get_date_completed();
$order->get_date_paid();

来源:https://businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/


另外

$order->get_date_created();

是“订单日期”,您可以在 WooCommerce 中更改(“编辑订单”)

【讨论】:

    【解决方案2】:

    不应直接访问订单属性。最好的方法是$order->get_date_completed()

    【讨论】:

      【解决方案3】:

      如果您有订单 ID,您可以使用 WC_Order 对象:

      $order = new WC_Order($order_id);
      $order_date = $order->order_date;
      

      【讨论】:

      • 或者,您可以使用wc_get_order( $order_id );
      • @helgatheviking ,在这种情况下使用 wc_get_order() 有什么好处?据我所知,wc_get_order() 最终会调用get_post(),因为提供的参数是数字。我可能遗漏了什么。
      • new WC_Order($order_id) 也将调用 get_post() 如果参数是数字。有点我说番茄,你说 tomahto.... 即,几乎没有区别。如果你强迫我,我会说wc_get_order() 可能不会改变,如果他们改变了WC_Order() 类的某些内容,那么包装器仍然可以工作。
      • 是否有“order_completed_date”字段?
      • 要回答我上面的问题,<?php echo $order->get_date_completed(); ?> 是我所需要的。
      猜你喜欢
      • 2016-05-10
      • 2020-08-17
      • 2021-07-31
      • 1970-01-01
      • 2019-07-08
      • 1970-01-01
      • 2016-10-23
      • 2016-07-08
      • 2014-03-05
      相关资源
      最近更新 更多