Merge pull request #13549 from woocommerce/order-date-functions
Order date functions
This commit is contained in:
commit
cf1ae98011
|
@ -599,6 +599,8 @@ abstract class WC_Data {
|
|||
try {
|
||||
if ( empty( $value ) ) {
|
||||
$datetime = null;
|
||||
} elseif ( is_a( $value, 'WC_DateTime' ) ) {
|
||||
$datetime = $value;
|
||||
} elseif ( is_numeric( $value ) ) {
|
||||
$datetime = new WC_DateTime( "@{$value}", new DateTimeZone( 'UTC' ) );
|
||||
$datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
|
|
|
@ -193,13 +193,13 @@ class WC_Meta_Box_Order_Data {
|
|||
|
||||
if ( $order->get_date_paid() ) {
|
||||
/* translators: 1: date 2: time */
|
||||
printf( ' ' . __( 'on %1$s @ %2$s', 'woocommerce' ), date_i18n( get_option( 'date_format' ), $order->get_date_paid() ), date_i18n( get_option( 'time_format' ), $order->get_date_paid() ) );
|
||||
printf( ' ' . __( 'on %1$s @ %2$s', 'woocommerce' ), wc_format_datetime( $order->get_date_paid() ), wc_format_datetime( $order->get_date_paid(), get_option( 'time_format' ) ) );
|
||||
}
|
||||
|
||||
echo '. ';
|
||||
}
|
||||
|
||||
if ( $ip_address = get_post_meta( $post->ID, '_customer_ip_address', true ) ) {
|
||||
if ( $ip_address = $order->get_customer_ip_address() ) {
|
||||
/* translators: %s: IP address */
|
||||
printf(
|
||||
__( 'Customer IP: %s', 'woocommerce' ),
|
||||
|
@ -522,9 +522,9 @@ class WC_Meta_Box_Order_Data {
|
|||
|
||||
// Update date.
|
||||
if ( empty( $_POST['order_date'] ) ) {
|
||||
$date = current_time( 'timestamp' );
|
||||
$date = current_time( 'timestamp', true );
|
||||
} else {
|
||||
$date = strtotime( $_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00' );
|
||||
$date = gmdate( 'Y-m-d H:i:s', strtotime( $_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00' ) );
|
||||
}
|
||||
|
||||
$props['date_created'] = $date;
|
||||
|
|
|
@ -14,7 +14,7 @@ $who_refunded = new WP_User( $refund->get_refunded_by() );
|
|||
<td class="name">
|
||||
<?php
|
||||
/* translators: 1: refund id 2: date */
|
||||
printf( __( 'Refund #%1$s - %2$s', 'woocommerce' ), $refund->get_id(), date_i18n( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), $refund->get_date_created() ) );
|
||||
printf( __( 'Refund #%1$s - %2$s', 'woocommerce' ), $refund->get_id(), wc_format_datetime( $order->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ) );
|
||||
|
||||
if ( $who_refunded->exists() ) {
|
||||
echo ' ' . esc_attr_x( 'by', 'Ex: Refund - $date >by< $username', 'woocommerce' ) . ' ' . '<abbr class="refund_by" title="' . sprintf( esc_attr__( 'ID: %d', 'woocommerce' ), absint( $who_refunded->ID ) ) . '">' . esc_attr( $who_refunded->display_name ) . '</abbr>' ;
|
||||
|
|
|
@ -133,7 +133,7 @@ class WC_Report_Customer_List extends WP_List_Table {
|
|||
|
||||
if ( ! empty( $orders ) ) {
|
||||
$order = $orders[0];
|
||||
return '<a href="' . admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() . '</a> – ' . date_i18n( get_option( 'date_format' ), $order->get_date_created() );
|
||||
return '<a href="' . admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() . '</a> – ' . wc_format_datetime( $order->get_date_created() );
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
|
|
|
@ -160,7 +160,9 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
|
|||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$data[ $key ] = $data[ $key ] ? wc_rest_prepare_date_response( get_gmt_from_date( date( 'Y-m-d H:i:s', $data[ $key ] ) ) ) : false;
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
// Format line items.
|
||||
|
@ -177,6 +179,9 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
|
|||
$data['fee_lines'], $data['coupon_lines']
|
||||
);
|
||||
|
||||
ksort( $data );
|
||||
|
||||
$data = array_merge( array( 'id' => $object->get_id() ), $data );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
@ -336,6 +341,12 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the order refund was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'amount' => array(
|
||||
'description' => __( 'Refund amount.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
|
|
@ -194,7 +194,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$this->request = $request;
|
||||
$data = array_merge( array( 'id' => $object->get_id() ), $object->get_data() );
|
||||
$data = $object->get_data();
|
||||
$format_decimal = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
|
||||
$format_date = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
|
||||
$format_line_items = array( 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines' );
|
||||
|
@ -206,7 +206,9 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$data[ $key ] = $data[ $key ] ? wc_rest_prepare_date_response( get_gmt_from_date( date( 'Y-m-d H:i:s', $data[ $key ] ) ) ) : false;
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
// Format the order status.
|
||||
|
@ -227,6 +229,9 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
ksort( $data );
|
||||
|
||||
$data = array_merge( array( 'id' => $object->get_id() ), $data );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
@ -776,12 +781,24 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the order was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( "The date the order was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'discount_total' => array(
|
||||
'description' => __( 'Total discount amount for the order.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
@ -993,11 +1010,25 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_completed_gmt' => array(
|
||||
'description' => __( "The date the order was completed, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_paid' => array(
|
||||
'description' => __( "The date the order has been paid, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_paid_gmt' => array(
|
||||
'description' => __( "The date the order has been paid, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'cart_hash' => array(
|
||||
'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
|
||||
|
|
|
@ -114,9 +114,9 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
$order_data = array(
|
||||
'id' => $order->get_id(),
|
||||
'order_number' => $order->get_order_number(),
|
||||
'created_at' => $this->server->format_datetime( $order->get_date_created(), false, true ),
|
||||
'updated_at' => $this->server->format_datetime( $order->get_date_modified(), false, true ),
|
||||
'completed_at' => $this->server->format_datetime( $order->get_date_completed(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $order->get_date_created() ? $order->get_date_created()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'updated_at' => $this->server->format_datetime( $order->get_date_modified() ? $order->get_date_modified()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'completed_at' => $this->server->format_datetime( $order->get_date_completed() ? $order->get_date_completed()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'status' => $order->get_status(),
|
||||
'currency' => $order->get_currency(),
|
||||
'total' => wc_format_decimal( $order->get_total(), 2 ),
|
||||
|
@ -133,7 +133,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
'payment_details' => array(
|
||||
'method_id' => $order->get_payment_method(),
|
||||
'method_title' => $order->get_payment_method_title(),
|
||||
'paid' => 0 < $order->get_date_paid(),
|
||||
'paid' => ! is_null( $order->get_date_paid() ),
|
||||
),
|
||||
'billing_address' => array(
|
||||
'first_name' => $order->get_billing_first_name(),
|
||||
|
|
|
@ -154,9 +154,9 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
$order_data = array(
|
||||
'id' => $order->get_id(),
|
||||
'order_number' => $order->get_order_number(),
|
||||
'created_at' => $this->server->format_datetime( $order->get_date_created(), false, true ),
|
||||
'updated_at' => $this->server->format_datetime( $order->get_date_modified(), false, true ),
|
||||
'completed_at' => $this->server->format_datetime( $order->get_date_completed(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $order->get_date_created() ? $order->get_date_created()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'updated_at' => $this->server->format_datetime( $order->get_date_modified() ? $order->get_date_modified()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'completed_at' => $this->server->format_datetime( $order->get_date_completed() ? $order->get_date_completed()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'status' => $order->get_status(),
|
||||
'currency' => $order->get_currency(),
|
||||
'total' => wc_format_decimal( $order->get_total(), $dp ),
|
||||
|
@ -171,7 +171,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
'payment_details' => array(
|
||||
'method_id' => $order->get_payment_method(),
|
||||
'method_title' => $order->get_payment_method_title(),
|
||||
'paid' => 0 < $order->get_date_paid(),
|
||||
'paid' => ! is_null( $order->get_date_paid() ),
|
||||
),
|
||||
'billing_address' => array(
|
||||
'first_name' => $order->get_billing_first_name(),
|
||||
|
@ -1539,7 +1539,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
|
||||
$order_refund = array(
|
||||
'id' => $refund->id,
|
||||
'created_at' => $this->server->format_datetime( $refund->get_date_created(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $refund->get_date_created() ? $refund->get_date_created()->getTimestamp() : 0, false, false ),
|
||||
'amount' => wc_format_decimal( $refund->get_amount(), 2 ),
|
||||
'reason' => $refund->get_reason(),
|
||||
'line_items' => $line_items,
|
||||
|
|
|
@ -161,9 +161,9 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
'id' => $order->get_id(),
|
||||
'order_number' => $order->get_order_number(),
|
||||
'order_key' => $order->get_order_key(),
|
||||
'created_at' => $this->server->format_datetime( $order->get_date_created(), false, true ),
|
||||
'updated_at' => $this->server->format_datetime( $order->get_date_modified(), false, true ),
|
||||
'completed_at' => $this->server->format_datetime( $order->get_date_completed(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $order->get_date_created() ? $order->get_date_created()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'updated_at' => $this->server->format_datetime( $order->get_date_modified() ? $order->get_date_modified()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'completed_at' => $this->server->format_datetime( $order->get_date_completed() ? $order->get_date_completed()->getTimestamp() : 0, false, false ), // API gives UTC times.
|
||||
'status' => $order->get_status(),
|
||||
'currency' => $order->get_currency(),
|
||||
'total' => wc_format_decimal( $order->get_total(), $dp ),
|
||||
|
@ -178,7 +178,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
'payment_details' => array(
|
||||
'method_id' => $order->get_payment_method(),
|
||||
'method_title' => $order->get_payment_method_title(),
|
||||
'paid' => 0 < $order->get_date_paid(),
|
||||
'paid' => ! is_null( $order->get_date_paid() ),
|
||||
),
|
||||
'billing_address' => array(
|
||||
'first_name' => $order->get_billing_first_name(),
|
||||
|
@ -1589,7 +1589,7 @@ class WC_API_Orders extends WC_API_Resource {
|
|||
|
||||
$order_refund = array(
|
||||
'id' => $refund->id,
|
||||
'created_at' => $this->server->format_datetime( $refund->get_date_created(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $refund->get_date_created() ? $refund->get_date_created()->getTimestamp() : 0, false, false ),
|
||||
'amount' => wc_format_decimal( $refund->get_amount(), 2 ),
|
||||
'reason' => $refund->get_reason(),
|
||||
'line_items' => $line_items,
|
||||
|
|
|
@ -139,8 +139,8 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'currency' => $order->get_currency(),
|
||||
'version' => $order->get_version(),
|
||||
'prices_include_tax' => $order->get_prices_include_tax(),
|
||||
'date_created' => wc_rest_prepare_date_response( $order->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $order->get_date_modified() ),
|
||||
'date_created' => wc_rest_prepare_date_response( $order->get_date_created() ), // v1 API used UTC.
|
||||
'date_modified' => wc_rest_prepare_date_response( $order->get_date_modified() ), // v1 API used UTC.
|
||||
'customer_id' => $order->get_customer_id(),
|
||||
'discount_total' => wc_format_decimal( $order->get_total_discount(), $dp ),
|
||||
'discount_tax' => wc_format_decimal( $order->get_discount_tax(), $dp ),
|
||||
|
@ -158,8 +158,8 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'customer_user_agent' => $order->get_customer_user_agent(),
|
||||
'created_via' => $order->get_created_via(),
|
||||
'customer_note' => $order->get_customer_note(),
|
||||
'date_completed' => wc_rest_prepare_date_response( $order->get_date_completed() ),
|
||||
'date_paid' => $order->get_date_paid() ? wc_rest_prepare_date_response( $order->get_date_paid() ) : '',
|
||||
'date_completed' => wc_rest_prepare_date_response( $order->get_date_completed(), false ), // v1 API used local time.
|
||||
'date_paid' => wc_rest_prepare_date_response( $order->get_date_paid(), false ), // v1 API used local time.
|
||||
'cart_hash' => $order->get_cart_hash(),
|
||||
'line_items' => array(),
|
||||
'tax_lines' => array(),
|
||||
|
@ -953,13 +953,13 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce' ),
|
||||
'description' => __( "The date the order was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'description' => __( "The date the order was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
|
|
@ -79,8 +79,8 @@ class WC_Order extends WC_Abstract_Order {
|
|||
'customer_user_agent' => '',
|
||||
'created_via' => '',
|
||||
'customer_note' => '',
|
||||
'date_completed' => '',
|
||||
'date_paid' => '',
|
||||
'date_completed' => null,
|
||||
'date_paid' => null,
|
||||
'cart_hash' => '',
|
||||
);
|
||||
|
||||
|
@ -114,7 +114,7 @@ class WC_Order extends WC_Abstract_Order {
|
|||
$this->set_transaction_id( $transaction_id );
|
||||
}
|
||||
if ( ! $this->get_date_paid( 'edit' ) ) {
|
||||
$this->set_date_paid( current_time( 'timestamp' ) );
|
||||
$this->set_date_paid( current_time( 'timestamp', true ) );
|
||||
}
|
||||
$this->set_status( apply_filters( 'woocommerce_payment_complete_order_status', $this->needs_processing() ? 'processing' : 'completed', $this->get_id(), $this ) );
|
||||
$this->save();
|
||||
|
@ -257,7 +257,7 @@ class WC_Order extends WC_Abstract_Order {
|
|||
*/
|
||||
public function maybe_set_date_paid( $date_paid = '' ) {
|
||||
if ( ! $this->get_date_paid( 'edit' ) && $this->has_status( array( 'processing', 'completed' ) ) ) {
|
||||
$this->set_date_paid( $date_paid ? $date_paid : current_time( 'timestamp' ) );
|
||||
$this->set_date_paid( $date_paid ? $date_paid : current_time( 'timestamp', true ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ class WC_Order extends WC_Abstract_Order {
|
|||
*/
|
||||
protected function maybe_set_date_completed() {
|
||||
if ( $this->has_status( 'completed' ) ) {
|
||||
$this->set_date_completed( current_time( 'timestamp' ) );
|
||||
$this->set_date_completed( current_time( 'timestamp', true ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -716,7 +716,7 @@ class WC_Order extends WC_Abstract_Order {
|
|||
* Get date_completed.
|
||||
*
|
||||
* @param string $context
|
||||
* @return int
|
||||
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_completed( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_completed', $context );
|
||||
|
@ -726,7 +726,7 @@ class WC_Order extends WC_Abstract_Order {
|
|||
* Get date_paid.
|
||||
*
|
||||
* @param string $context
|
||||
* @return int
|
||||
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_paid( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_paid', $context );
|
||||
|
@ -1155,21 +1155,21 @@ class WC_Order extends WC_Abstract_Order {
|
|||
/**
|
||||
* Set date_completed.
|
||||
*
|
||||
* @param string $timestamp
|
||||
* @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_date_completed( $timestamp ) {
|
||||
$this->set_prop( 'date_completed', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_completed( $date = null ) {
|
||||
$this->set_date_prop( 'date_completed', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_paid.
|
||||
*
|
||||
* @param string $timestamp
|
||||
* @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_date_paid( $timestamp ) {
|
||||
$this->set_prop( 'date_paid', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_paid( $date = null ) {
|
||||
$this->set_date_prop( 'date_paid', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -387,7 +387,7 @@ class WC_Structured_Data {
|
|||
$markup['url'] = $order_url;
|
||||
$markup['orderStatus'] = isset( $order_status[ $order->get_status() ] ) ? $order_status[ $order->get_status() ] : '';
|
||||
$markup['orderNumber'] = $order->get_order_number();
|
||||
$markup['orderDate'] = date( 'c', $order->get_date_created() );
|
||||
$markup['orderDate'] = $order->get_date_created()->format( 'c' );
|
||||
$markup['acceptedOffer'] = $markup_offers;
|
||||
$markup['discount'] = $order->get_total_discount();
|
||||
$markup['discountCurrency'] = $order->get_currency();
|
||||
|
|
|
@ -89,8 +89,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
|||
$id = $order->get_id();
|
||||
$order->set_props( array(
|
||||
'parent_id' => $post_object->post_parent,
|
||||
'date_created' => $post_object->post_date_gmt,
|
||||
'date_modified' => $post_object->post_modified_gmt,
|
||||
'date_created' => strtotime( $post_object->post_date_gmt ),
|
||||
'date_modified' => strtotime( $post_object->post_modified_gmt ),
|
||||
'status' => $post_object->post_status,
|
||||
) );
|
||||
|
||||
|
|
|
@ -88,7 +88,17 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
*/
|
||||
protected function read_order_data( &$order, $post_object ) {
|
||||
parent::read_order_data( $order, $post_object );
|
||||
$id = $order->get_id();
|
||||
$id = $order->get_id();
|
||||
$date_completed = get_post_meta( $id, '_date_completed', true );
|
||||
$date_paid = get_post_meta( $id, '_date_paid', true );
|
||||
|
||||
if ( ! $date_completed ) {
|
||||
$date_completed = get_post_meta( $id, '_completed_date', true );
|
||||
}
|
||||
|
||||
if ( ! $date_paid ) {
|
||||
$date_paid = get_post_meta( $id, '_paid_date', true );
|
||||
}
|
||||
|
||||
$order->set_props( array(
|
||||
'order_key' => get_post_meta( $id, '_order_key', true ),
|
||||
|
@ -119,8 +129,8 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
'customer_ip_address' => get_post_meta( $id, '_customer_ip_address', true ),
|
||||
'customer_user_agent' => get_post_meta( $id, '_customer_user_agent', true ),
|
||||
'created_via' => get_post_meta( $id, '_created_via', true ),
|
||||
'date_completed' => get_post_meta( $id, '_completed_date', true ),
|
||||
'date_paid' => get_post_meta( $id, '_paid_date', true ),
|
||||
'date_completed' => $date_completed,
|
||||
'date_paid' => $date_paid,
|
||||
'cart_hash' => get_post_meta( $id, '_cart_hash', true ),
|
||||
'customer_note' => $post_object->post_excerpt,
|
||||
) );
|
||||
|
@ -153,15 +163,34 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
'_customer_ip_address' => 'customer_ip_address',
|
||||
'_customer_user_agent' => 'customer_user_agent',
|
||||
'_created_via' => 'created_via',
|
||||
'_completed_date' => 'date_completed',
|
||||
'_paid_date' => 'date_paid',
|
||||
'_date_completed' => 'date_completed',
|
||||
'_date_paid' => 'date_paid',
|
||||
'_cart_hash' => 'cart_hash',
|
||||
);
|
||||
|
||||
$props_to_update = $this->get_props_to_update( $order, $meta_key_to_props );
|
||||
|
||||
foreach ( $props_to_update as $meta_key => $prop ) {
|
||||
$value = $order->{"get_$prop"}( 'edit' );
|
||||
update_post_meta( $id, $meta_key, $value );
|
||||
|
||||
if ( 'date_paid' === $prop ) {
|
||||
// In 2.7.x we store this as a UTC timestamp.
|
||||
update_post_meta( $id, $meta_key, ! is_null( $value ) ? $value->getTimestamp() : '', true );
|
||||
|
||||
// In 2.6.x date_paid was stored as _paid_date in local mysql format.
|
||||
update_post_meta( $id, '_paid_date', ! is_null( $value ) ? $value->date( 'Y-m-d H:i:s' ) : '', true );
|
||||
|
||||
} elseif ( 'date_completed' === $prop ) {
|
||||
// In 2.7.x we store this as a UTC timestamp.
|
||||
update_post_meta( $id, $meta_key, ! is_null( $value ) ? $value->getTimestamp() : '', true );
|
||||
|
||||
// In 2.6.x date_paid was stored as _paid_date in local mysql format.
|
||||
update_post_meta( $id, '_completed_date', ! is_null( $value ) ? $value->date( 'Y-m-d H:i:s' ) : '', true );
|
||||
|
||||
} else {
|
||||
update_post_meta( $id, $meta_key, $value );
|
||||
}
|
||||
|
||||
$updated_props[] = $prop;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class WC_Email_Cancelled_Order extends WC_Email {
|
|||
$this->object = $order;
|
||||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
|
|||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
|
|||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class WC_Email_Customer_Note extends WC_Email {
|
|||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
} else {
|
||||
return;
|
||||
|
|
|
@ -58,7 +58,7 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email {
|
|||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
|
|||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
|
|||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class WC_Email_Failed_Order extends WC_Email {
|
|||
$this->object = $order;
|
||||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class WC_Email_New_Order extends WC_Email {
|
|||
$this->object = $order;
|
||||
$this->find['order-date'] = '{order_date}';
|
||||
$this->find['order-number'] = '{order_number}';
|
||||
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
|
||||
$this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() );
|
||||
$this->replace['order-number'] = $this->object->get_order_number();
|
||||
}
|
||||
|
||||
|
|
|
@ -407,13 +407,13 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
|
|||
wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '2.7' );
|
||||
|
||||
if ( 'completed_date' === $key ) {
|
||||
return date( 'Y-m-d H:i:s', $this->get_date_completed() );
|
||||
return $this->get_date_completed() ? gmdate( 'Y-m-d H:i:s', $this->get_date_completed()->getOffsetTimestamp() ) : '';
|
||||
} elseif ( 'paid_date' === $key ) {
|
||||
return $this->get_date_paid();
|
||||
return $this->get_date_paid() ? gmdate( 'Y-m-d H:i:s', $this->get_date_paid()->getOffsetTimestamp() ) : '';
|
||||
} elseif ( 'modified_date' === $key ) {
|
||||
return date( 'Y-m-d H:i:s', $this->get_date_modified() );
|
||||
return $this->get_date_modified() ? gmdate( 'Y-m-d H:i:s', $this->get_date_modified()->getOffsetTimestamp() ) : '';
|
||||
} elseif ( 'order_date' === $key ) {
|
||||
return date( 'Y-m-d H:i:s', $this->get_date_created() );
|
||||
return $this->get_date_created() ? gmdate( 'Y-m-d H:i:s', $this->get_date_created()->getOffsetTimestamp() ) : '';
|
||||
} elseif ( 'id' === $key ) {
|
||||
return $this->get_id();
|
||||
} elseif ( 'post' === $key ) {
|
||||
|
|
|
@ -138,7 +138,7 @@ class WC_Shortcode_Checkout {
|
|||
</li>
|
||||
<li class="date">
|
||||
<?php _e( 'Date:', 'woocommerce' ); ?>
|
||||
<strong><?php echo date_i18n( get_option( 'date_format' ), $order->get_date_created() ); ?></strong>
|
||||
<strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
|
||||
</li>
|
||||
<li class="total">
|
||||
<?php _e( 'Total:', 'woocommerce' ); ?>
|
||||
|
|
|
@ -1023,3 +1023,21 @@ function wc_format_dimensions( $dimensions ) {
|
|||
|
||||
return apply_filters( 'woocommerce_format_dimensions', $dimension_string, $dimensions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a date for output.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WC_DateTime $date
|
||||
* @param string $format Defaults to the wc_date_format function if not set.
|
||||
* @return string
|
||||
*/
|
||||
function wc_format_datetime( $date, $format = '' ) {
|
||||
if ( ! $format ) {
|
||||
$format = wc_date_format();
|
||||
}
|
||||
if ( ! is_a( $date, 'WC_DateTime' ) ) {
|
||||
return '';
|
||||
}
|
||||
return $date->date_i18n( $format );
|
||||
}
|
||||
|
|
|
@ -377,8 +377,8 @@ function wc_downloadable_file_permission( $download_id, $product, $order, $qty =
|
|||
$expiry = $product->get_download_expiry();
|
||||
|
||||
if ( $expiry > 0 ) {
|
||||
$order_completed_date = date_i18n( "Y-m-d", $order->get_date_completed() );
|
||||
$download->set_access_expires( strtotime( $order_completed_date . ' + ' . $expiry . ' DAY' ) );
|
||||
$from_date = $order->get_date_completed() ? $order->get_date_completed()->format( 'Y-m-d' ) : current_time( 'mysql', true );
|
||||
$download->set_access_expires( strtotime( $from_date . ' + ' . $expiry . ' DAY' ) );
|
||||
}
|
||||
|
||||
return $download->save();
|
||||
|
|
|
@ -15,32 +15,31 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
|
||||
* Parses and formats a date for ISO8601/RFC3339.
|
||||
*
|
||||
* Required WP 4.4 or later.
|
||||
* See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @param string $date
|
||||
* @since 2.6.0
|
||||
* @param string|null|WC_DateTime $date
|
||||
* @param bool Send false to get local/offset time.
|
||||
* @return string|null ISO8601/RFC3339 formatted datetime.
|
||||
*/
|
||||
function wc_rest_prepare_date_response( $date ) {
|
||||
if ( false === strpos( $date, '-' ) ) {
|
||||
$date = date( 'Y-m-d H:i:s', $date );
|
||||
function wc_rest_prepare_date_response( $date, $utc = true ) {
|
||||
if ( is_numeric( $date ) ) {
|
||||
$date = new WC_DateTime( "@$date", new DateTimeZone( 'UTC' ) );
|
||||
$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
} elseif ( is_string( $date ) ) {
|
||||
$date = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) );
|
||||
$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
}
|
||||
|
||||
// Check if mysql_to_rfc3339 exists first!
|
||||
if ( ! function_exists( 'mysql_to_rfc3339' ) ) {
|
||||
if ( ! is_a( $date, 'WC_DateTime' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return null if $date is empty/zeros.
|
||||
if ( '0000-00-00 00:00:00' === $date || empty( $date ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return the formatted datetime.
|
||||
return mysql_to_rfc3339( $date );
|
||||
// Get timestamp before changing timezone to UTC.
|
||||
return gmdate( 'Y-m-d\TH:i:s', $utc ? $date->getTimestamp() : $date->getOffsetTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,7 +49,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
<li class="woocommerce-order-overview__date date">
|
||||
<?php _e( 'Date:', 'woocommerce' ); ?>
|
||||
<strong><?php echo date_i18n( get_option( 'date_format' ), $order->get_date_created() ); ?></strong>
|
||||
<strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
|
||||
</li>
|
||||
|
||||
<li class="woocommerce-order-overview__total total">
|
||||
|
|
|
@ -25,7 +25,7 @@ do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plai
|
|||
<?php if ( ! $sent_to_admin ) : ?>
|
||||
<h2><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></h2>
|
||||
<?php else : ?>
|
||||
<h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', date_i18n( 'c', $order->get_date_created() ), date_i18n( wc_date_format(), $order->get_date_created() ) ); ?>)</h2>
|
||||
<h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ); ?>)</h2>
|
||||
<?php endif; ?>
|
||||
|
||||
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
|
||||
|
|
|
@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email );
|
||||
|
||||
echo strtoupper( sprintf( __( 'Order number: %s', 'woocommerce' ), $order->get_order_number() ) ) . "\n";
|
||||
echo date_i18n( __( 'jS F Y', 'woocommerce' ), $order->get_date_created() ) . "\n";
|
||||
echo wc_format_datetime( $order->get_date_created() ) . "\n";
|
||||
echo "\n" . wc_get_email_order_items( $order, array(
|
||||
'show_sku' => $sent_to_admin,
|
||||
'show_image' => false,
|
||||
|
|
|
@ -56,7 +56,7 @@ if ( $customer_orders ) : ?>
|
|||
</a>
|
||||
|
||||
<?php elseif ( 'order-date' === $column_id ) : ?>
|
||||
<time datetime="<?php echo esc_attr( date( 'Y-m-d', $order->get_date_created() ) ); ?>" title="<?php echo esc_attr( $order->get_date_created() ); ?>"><?php echo esc_html( date_i18n( get_option( 'date_format' ), $order->get_date_created() ) ); ?></time>
|
||||
<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>
|
||||
|
||||
<?php elseif ( 'order-status' === $column_id ) : ?>
|
||||
<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>
|
||||
|
|
|
@ -52,7 +52,7 @@ do_action( 'woocommerce_before_account_orders', $has_orders ); ?>
|
|||
</a>
|
||||
|
||||
<?php elseif ( 'order-date' === $column_id ) : ?>
|
||||
<time datetime="<?php echo esc_attr( date( 'Y-m-d', $order->get_date_created() ) ); ?>" title="<?php echo esc_attr( $order->get_date_created() ); ?>"><?php echo esc_html( date_i18n( get_option( 'date_format' ), $order->get_date_created() ) ); ?></time>
|
||||
<time datetime="<?php echo esc_attr( $order->get_date_created()->date( 'c' ) ); ?>"><?php echo esc_html( wc_format_datetime( $order->get_date_created() ) ); ?></time>
|
||||
|
||||
<?php elseif ( 'order-status' === $column_id ) : ?>
|
||||
<?php echo esc_html( wc_get_order_status_name( $order->get_status() ) ); ?>
|
||||
|
|
|
@ -28,7 +28,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
printf(
|
||||
__( 'Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce' ),
|
||||
'<mark class="order-number">' . $order->get_order_number() . '</mark>',
|
||||
'<mark class="order-date">' . date_i18n( get_option( 'date_format' ), $order->get_date_created() ) . '</mark>',
|
||||
'<mark class="order-date">' . wc_format_datetime( $order->get_date_created() ) . '</mark>',
|
||||
'<mark class="order-status">' . wc_get_order_status_name( $order->get_status() ) . '</mark>'
|
||||
);
|
||||
?></p>
|
||||
|
|
|
@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
echo wp_kses_post( apply_filters( 'woocommerce_order_tracking_status', sprintf(
|
||||
__( 'Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce' ),
|
||||
'<mark class="order-number">' . $order->get_order_number() . '</mark>',
|
||||
'<mark class="order-date">' . date_i18n( get_option( 'date_format' ), $order->get_date_created() ) . '</mark>',
|
||||
'<mark class="order-date">' . wc_format_datetime( $order->get_date_created() ) . '</mark>',
|
||||
'<mark class="order-status">' . wc_get_order_status_name( $order->get_status() ) . '</mark>'
|
||||
) ) );
|
||||
?></p>
|
||||
|
|
|
@ -411,7 +411,7 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
|
|||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertEquals( 38, count( $properties ) );
|
||||
$this->assertEquals( 42, count( $properties ) );
|
||||
$this->assertArrayHasKey( 'id', $properties );
|
||||
wp_delete_post( $order->get_id(), true );
|
||||
}
|
||||
|
|
|
@ -1030,10 +1030,10 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
|
|||
function test_get_date_completed() {
|
||||
$object = new WC_Order();
|
||||
$object->set_date_completed( '2016-12-12' );
|
||||
$this->assertEquals( '1481500800', $object->get_date_completed() );
|
||||
$this->assertEquals( '1481500800', $object->get_date_completed()->getOffsetTimestamp() );
|
||||
|
||||
$object->set_date_completed( '1481500800' );
|
||||
$this->assertEquals( 1481500800, $object->get_date_completed() );
|
||||
$this->assertEquals( 1481500800, $object->get_date_completed()->getTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1043,10 +1043,10 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
|
|||
$object = new WC_Order();
|
||||
$set_to = 'PayPal';
|
||||
$object->set_date_paid( '2016-12-12' );
|
||||
$this->assertEquals( 1481500800, $object->get_date_paid() );
|
||||
$this->assertEquals( 1481500800, $object->get_date_paid()->getOffsetTimestamp() );
|
||||
|
||||
$object->set_date_paid( '1481500800' );
|
||||
$this->assertEquals( 1481500800, $object->get_date_paid() );
|
||||
$this->assertEquals( 1481500800, $object->get_date_paid()->getTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue