Merge pull request #13577 from woocommerce/fix-13498
Timezone/Date method handling
This commit is contained in:
commit
75a5b062cf
File diff suppressed because one or more lines are too long
|
@ -563,7 +563,7 @@ abstract class WC_Data {
|
|||
* @since 2.7.0
|
||||
*/
|
||||
public function apply_changes() {
|
||||
$this->data = array_replace_recursive( $this->data, $this->changes );
|
||||
$this->data = array_replace_recursive( $this->data, $this->changes );
|
||||
$this->changes = array();
|
||||
}
|
||||
|
||||
|
@ -592,15 +592,40 @@ abstract class WC_Data {
|
|||
$value = null;
|
||||
|
||||
if ( array_key_exists( $prop, $this->data ) ) {
|
||||
$value = isset( $this->changes[ $prop ] ) ? $this->changes[ $prop ] : $this->data[ $prop ];
|
||||
$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
|
||||
|
||||
if ( 'view' === $context ) {
|
||||
$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a date prop whilst handling formatting and datatime objects.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $prop Name of prop to set.
|
||||
* @param string|integer $value Value of the prop.
|
||||
*/
|
||||
protected function set_date_prop( $prop, $value ) {
|
||||
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() ) );
|
||||
} else {
|
||||
$datetime = new WC_DateTime( $value, new DateTimeZone( wc_timezone_string() ) );
|
||||
$datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
}
|
||||
$this->set_prop( $prop, $datetime );
|
||||
} catch ( Exception $e ) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* When invalid data is found, throw an exception unless reading from the DB.
|
||||
*
|
||||
|
|
|
@ -34,8 +34,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
'currency' => '',
|
||||
'version' => '',
|
||||
'prices_include_tax' => false,
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'date_created' => null,
|
||||
'date_modified' => null,
|
||||
'discount_total' => 0,
|
||||
'discount_tax' => 0,
|
||||
'shipping_total' => 0,
|
||||
|
@ -255,7 +255,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
* Get date_created.
|
||||
*
|
||||
* @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_created( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_created', $context );
|
||||
|
@ -265,7 +265,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
* Get date_modified.
|
||||
*
|
||||
* @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_modified( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_modified', $context );
|
||||
|
@ -524,21 +524,21 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
/**
|
||||
* Set date_created.
|
||||
*
|
||||
* @param string $timestamp 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_created( $timestamp ) {
|
||||
$this->set_prop( 'date_created', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_created( $date = null ) {
|
||||
$this->set_date_prop( 'date_created', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_modified.
|
||||
*
|
||||
* @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_modified( $timestamp ) {
|
||||
$this->set_prop( 'date_modified', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_modified( $date = null ) {
|
||||
$this->set_date_prop( 'date_modified', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,8 +47,8 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
protected $data = array(
|
||||
'name' => '',
|
||||
'slug' => '',
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'date_created' => null,
|
||||
'date_modified' => null,
|
||||
'status' => false,
|
||||
'featured' => false,
|
||||
'catalog_visibility' => 'visible',
|
||||
|
@ -58,8 +58,8 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
'price' => '',
|
||||
'regular_price' => '',
|
||||
'sale_price' => '',
|
||||
'date_on_sale_from' => '',
|
||||
'date_on_sale_to' => '',
|
||||
'date_on_sale_from' => null,
|
||||
'date_on_sale_to' => null,
|
||||
'total_sales' => '0',
|
||||
'tax_status' => 'taxable',
|
||||
'tax_class' => '',
|
||||
|
@ -174,7 +174,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
*
|
||||
* @since 2.7.0
|
||||
* @param string $context
|
||||
* @return string Timestamp.
|
||||
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_created( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_created', $context );
|
||||
|
@ -185,7 +185,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
*
|
||||
* @since 2.7.0
|
||||
* @param string $context
|
||||
* @return string Timestamp.
|
||||
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_modified( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_modified', $context );
|
||||
|
@ -291,7 +291,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
*
|
||||
* @since 2.7.0
|
||||
* @param string $context
|
||||
* @return string
|
||||
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_on_sale_from( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_on_sale_from', $context );
|
||||
|
@ -302,7 +302,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
*
|
||||
* @since 2.7.0
|
||||
* @param string $context
|
||||
* @return string
|
||||
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_on_sale_to( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_on_sale_to', $context );
|
||||
|
@ -708,20 +708,20 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* Set product created date.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $timestamp 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.
|
||||
*/
|
||||
public function set_date_created( $timestamp ) {
|
||||
$this->set_prop( 'date_created', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_created( $date = null ) {
|
||||
$this->set_date_prop( 'date_created', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product modified date.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $timestamp 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.
|
||||
*/
|
||||
public function set_date_modified( $timestamp ) {
|
||||
$this->set_prop( 'date_modified', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_modified( $date = null ) {
|
||||
$this->set_date_prop( 'date_modified', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -829,20 +829,20 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* Set date on sale from.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $timestamp Sale from date.
|
||||
* @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.
|
||||
*/
|
||||
public function set_date_on_sale_from( $timestamp ) {
|
||||
$this->set_prop( 'date_on_sale_from', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_on_sale_from( $date = null ) {
|
||||
$this->set_date_prop( 'date_on_sale_from', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date on sale to.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $timestamp Sale to date.
|
||||
* @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.
|
||||
*/
|
||||
public function set_date_on_sale_to( $timestamp ) {
|
||||
$this->set_prop( 'date_on_sale_to', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_on_sale_to( $date = null ) {
|
||||
$this->set_date_prop( 'date_on_sale_to', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1409,17 +1409,16 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
if ( '' !== (string) $this->get_sale_price( $context ) && $this->get_regular_price( $context ) > $this->get_sale_price( $context ) ) {
|
||||
$on_sale = true;
|
||||
|
||||
if ( '' !== (string) $this->get_date_on_sale_from( $context ) && $this->get_date_on_sale_from( $context ) > strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||
if ( $this->get_date_on_sale_from( $context ) && $this->get_date_on_sale_from( $context )->getTimestamp() > time() ) {
|
||||
$on_sale = false;
|
||||
}
|
||||
|
||||
if ( '' !== (string) $this->get_date_on_sale_to( $context ) && $this->get_date_on_sale_to( $context ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
||||
if ( $this->get_date_on_sale_to( $context ) && $this->get_date_on_sale_to( $context )->getTimestamp() < time() ) {
|
||||
$on_sale = false;
|
||||
}
|
||||
} else {
|
||||
$on_sale = false;
|
||||
}
|
||||
|
||||
return 'view' === $context ? apply_filters( 'woocommerce_product_is_on_sale', $on_sale, $this ) : $on_sale;
|
||||
}
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ class WC_Admin_Post_Types {
|
|||
$expiry_date = $the_coupon->get_date_expires();
|
||||
|
||||
if ( $expiry_date ) {
|
||||
echo esc_html( date_i18n( 'F j, Y', $expiry_date ) );
|
||||
echo esc_html( $expiry_date->date_i18n( 'F j, Y' ) );
|
||||
} else {
|
||||
echo '–';
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ class WC_Admin_Post_Types {
|
|||
printf( '<mark class="%s tips" data-tip="%s">%s</mark>', esc_attr( sanitize_html_class( $the_order->get_status() ) ), esc_attr( wc_get_order_status_name( $the_order->get_status() ) ), esc_html( wc_get_order_status_name( $the_order->get_status() ) ) );
|
||||
break;
|
||||
case 'order_date' :
|
||||
printf( '<time datetime="%s">%s</time>', esc_attr( date( 'c', $the_order->get_date_created() ) ), esc_html( date_i18n( __( 'Y-m-d', 'woocommerce' ), $the_order->get_date_created() ) ) );
|
||||
printf( '<time datetime="%s">%s</time>', esc_attr( $the_order->get_date_created()->date( 'c' ) ), esc_html( $the_order->get_date_created()->date_i18n( __( 'Y-m-d', 'woocommerce' ) ) ) );
|
||||
break;
|
||||
case 'customer_message' :
|
||||
if ( $the_order->get_customer_note() ) {
|
||||
|
|
|
@ -92,7 +92,7 @@ class WC_Meta_Box_Coupon_Data {
|
|||
}
|
||||
|
||||
// Expiry date
|
||||
$expiry_date = $coupon->get_date_expires() ? date( 'Y-m-d', $coupon->get_date_expires() ) : '';
|
||||
$expiry_date = $coupon->get_date_expires() ? $coupon->get_date_expires()->date( 'Y-m-d' ) : '';
|
||||
woocommerce_wp_text_input( array(
|
||||
'id' => 'expiry_date',
|
||||
'value' => esc_attr( $expiry_date ),
|
||||
|
|
|
@ -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' ),
|
||||
|
@ -530,9 +530,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;
|
||||
|
|
|
@ -29,7 +29,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
</td>
|
||||
<td>
|
||||
<label><?php _e( 'Access expires', 'woocommerce' ); ?></label>
|
||||
<input type="text" class="short date-picker" name="access_expires[<?php echo $loop; ?>]" value="<?php echo $download->get_access_expires() > 0 ? date_i18n( 'Y-m-d', $download->get_access_expires() ) : ''; ?>" maxlength="10" placeholder="<?php esc_attr_e( 'Never', 'woocommerce' ); ?>" pattern="<?php echo esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ); ?>" />
|
||||
<input type="text" class="short date-picker" name="access_expires[<?php echo $loop; ?>]" value="<?php echo ! is_null( $download->get_access_expires() ) ? date_i18n( 'Y-m-d', $download->get_access_expires()->getTimestamp() ) : ''; ?>" maxlength="10" placeholder="<?php esc_attr_e( 'Never', 'woocommerce' ); ?>" pattern="<?php echo esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ); ?>" />
|
||||
</td>
|
||||
<td>
|
||||
<label><?php _e( 'Customer download link', 'woocommerce' ); ?></label>
|
||||
|
|
|
@ -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>' ;
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
'description' => '<a href="#" class="sale_schedule">' . __( 'Schedule', 'woocommerce' ) . '</a>',
|
||||
) );
|
||||
|
||||
$sale_price_dates_from = ( $date = $product_object->get_date_on_sale_from( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = ( $date = $product_object->get_date_on_sale_to( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_from = $product_object->get_date_on_sale_from( 'edit' ) && ( $date = $product_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = $product_object->get_date_on_sale_to( 'edit' ) && ( $date = $product_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
|
||||
echo '<p class="form-field sale_price_dates_fields">
|
||||
<label for="_sale_price_dates_from">' . __( 'Sale price dates', 'woocommerce' ) . '</label>
|
||||
|
|
|
@ -125,8 +125,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
'wrapper_class' => 'form-row form-row-last',
|
||||
) );
|
||||
|
||||
$sale_price_dates_from = ( $date = $variation_object->get_date_on_sale_from( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = ( $date = $variation_object->get_date_on_sale_to( 'edit' ) ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_from = $variation_object->get_date_on_sale_from( 'edit' ) && ( $date = $variation_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
$sale_price_dates_to = $variation_object->get_date_on_sale_to( 'edit' ) && ( $date = $variation_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
|
||||
|
||||
echo '<div class="form-field sale_price_dates_fields hidden">
|
||||
<p class="form-row form-row-first">
|
||||
|
|
|
@ -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 '-';
|
||||
}
|
||||
|
|
|
@ -128,14 +128,13 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Prepare a single coupon output for response.
|
||||
* Get formatted item data.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WC_Data $object Object data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
* @since 3.0.0
|
||||
* @param WC_Data $object WC_Data instance.
|
||||
* @return array
|
||||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
protected function get_formatted_item_data( $object ) {
|
||||
$data = $object->get_data();
|
||||
|
||||
$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
|
||||
|
@ -149,7 +148,9 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_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 ] ) ) ) : null;
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
// Format null values.
|
||||
|
@ -157,6 +158,47 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
$data[ $key ] = $data[ $key ] ? $data[ $key ] : null;
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $object->get_id(),
|
||||
'code' => $data['code'],
|
||||
'amount' => $data['amount'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'discount_type' => $data['discount_type'],
|
||||
'description' => $data['description'],
|
||||
'date_expires' => $data['date_expires'],
|
||||
'date_expires_gmt' => $data['date_expires_gmt'],
|
||||
'usage_count' => $data['usage_count'],
|
||||
'individual_use' => $data['individual_use'],
|
||||
'product_ids' => $data['product_ids'],
|
||||
'excluded_product_ids' => $data['excluded_product_ids'],
|
||||
'usage_limit' => $data['usage_limit'],
|
||||
'usage_limit_per_user' => $data['usage_limit_per_user'],
|
||||
'limit_usage_to_x_items' => $data['limit_usage_to_x_items'],
|
||||
'free_shipping' => $data['free_shipping'],
|
||||
'product_categories' => $data['product_categories'],
|
||||
'excluded_product_categories' => $data['excluded_product_categories'],
|
||||
'exclude_sale_items' => $data['exclude_sale_items'],
|
||||
'minimum_amount' => $data['minimum_amount'],
|
||||
'maximum_amount' => $data['maximum_amount'],
|
||||
'email_restrictions' => $data['email_restrictions'],
|
||||
'used_by' => $data['used_by'],
|
||||
'meta_data' => $data['meta_data'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a single coupon output for response.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WC_Data $object Object data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$data = $this->get_formatted_item_data( $object );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
@ -307,12 +349,24 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the coupon 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 coupon was last modified, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'discount_type' => array(
|
||||
'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
@ -326,7 +380,12 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_expires' => array(
|
||||
'description' => __( 'UTC DateTime when the coupon expires.', 'woocommerce' ),
|
||||
'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_expires_gmt' => array(
|
||||
'description' => __( "The date the coupon expires, as GMT.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
|
|
|
@ -32,14 +32,24 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Customer_Downloads_V
|
|||
/**
|
||||
* Prepare a single download output for response.
|
||||
*
|
||||
* @param stdObject $download Download object.
|
||||
* @param stdClass $download Download object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $download, $request ) {
|
||||
$data = (array) $download;
|
||||
$data['access_expires'] = $data['access_expires'] ? wc_rest_prepare_date_response( $data['access_expires'] ) : 'never';
|
||||
$data['downloads_remaining'] = '' === $data['downloads_remaining'] ? 'unlimited' : $data['downloads_remaining'];
|
||||
$data = array(
|
||||
'download_id' => $download->download_id,
|
||||
'download_url' => $download->download_url,
|
||||
'product_id' => $download->product_id,
|
||||
'product_name' => $download->product_name,
|
||||
'download_name' => $download->download_name,
|
||||
'order_id' => $download->order_id,
|
||||
'order_key' => $download->order_key,
|
||||
'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining,
|
||||
'access_expires' => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never',
|
||||
'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never',
|
||||
'file' => $download->file,
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
|
@ -54,7 +64,7 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Customer_Downloads_V
|
|||
* Filter customer download data returned from the REST API.
|
||||
*
|
||||
* @param WP_REST_Response $response The response object.
|
||||
* @param stdObject $download Download object used to create response.
|
||||
* @param stdClass $download Download object used to create response.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
*/
|
||||
return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request );
|
||||
|
@ -71,14 +81,14 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Customer_Downloads_V
|
|||
'title' => 'customer_download',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'download_url' => array(
|
||||
'description' => __( 'Download file URL.', 'woocommerce' ),
|
||||
'download_id' => array(
|
||||
'description' => __( 'Download ID (MD5).', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'download_id' => array(
|
||||
'description' => __( 'Download ID (MD5).', 'woocommerce' ),
|
||||
'download_url' => array(
|
||||
'description' => __( 'Download file URL.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
|
@ -125,6 +135,12 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Customer_Downloads_V
|
|||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'access_expires_gmt' => array(
|
||||
'description' => __( "The date when the download access expires, as GMT.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'file' => array(
|
||||
'description' => __( 'File details.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
|
|
|
@ -29,6 +29,45 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
*/
|
||||
protected $namespace = 'wc/v2';
|
||||
|
||||
/**
|
||||
* Get formatted item data.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WC_Data $object WC_Data instance.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_formatted_item_data( $object ) {
|
||||
$data = $object->get_data();
|
||||
$format_date = array( 'date_created', 'date_modified' );
|
||||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $object->get_id(),
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'email' => $data['email'],
|
||||
'first_name' => $data['first_name'],
|
||||
'last_name' => $data['last_name'],
|
||||
'role' => $data['role'],
|
||||
'username' => $data['username'],
|
||||
'billing' => $data['billing'],
|
||||
'shipping' => $data['shipping'],
|
||||
'is_paying_customer' => $data['is_paying_customer'],
|
||||
'orders_count' => $object->get_order_count(),
|
||||
'total_spent' => $object->get_total_spent(),
|
||||
'avatar_url' => $object->get_avatar_url(),
|
||||
'meta_data' => $data['meta_data'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a single customer output for response.
|
||||
*
|
||||
|
@ -38,28 +77,11 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
*/
|
||||
public function prepare_item_for_response( $user_data, $request ) {
|
||||
$customer = new WC_Customer( $user_data->ID );
|
||||
$data = $customer->get_data();
|
||||
$format_date = array( 'date_created', 'date_modified' );
|
||||
$meta_data = $data['meta_data'];
|
||||
unset( $data['meta_data'] );
|
||||
|
||||
// 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 ] ) ) ) : null;
|
||||
}
|
||||
|
||||
// Additional non-crud data.
|
||||
$data['orders_count'] = $customer->get_order_count();
|
||||
$data['total_spent'] = $customer->get_total_spent();
|
||||
$data['avatar_url'] = $customer->get_avatar_url();
|
||||
|
||||
// Includes meta_data as last item.
|
||||
$data['meta_data'] = $meta_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 );
|
||||
$response = rest_ensure_response( $data );
|
||||
$data = $this->get_formatted_item_data( $customer );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$response = rest_ensure_response( $data );
|
||||
$response->add_links( $this->prepare_links( $user_data ) );
|
||||
|
||||
/**
|
||||
|
@ -114,12 +136,24 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_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 customer 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,
|
||||
),
|
||||
'email' => array(
|
||||
'description' => __( 'The email address for the customer.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
|
|
@ -128,6 +128,48 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
|
|||
return wc_get_order( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted item data.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WC_Data $object WC_Data instance.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_formatted_item_data( $object ) {
|
||||
$data = $object->get_data();
|
||||
$format_decimal = array( 'amount' );
|
||||
$format_date = array( 'date_created' );
|
||||
$format_line_items = array( 'line_items' );
|
||||
|
||||
// Format decimal values.
|
||||
foreach ( $format_decimal as $key ) {
|
||||
$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
|
||||
}
|
||||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
// Format line items.
|
||||
foreach ( $format_line_items as $key ) {
|
||||
$data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) );
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $object->get_id(),
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'amount' => $data['amount'],
|
||||
'reason' => $data['reason'],
|
||||
'refunded_by' => $data['refunded_by'],
|
||||
'meta_data' => $data['meta_data'],
|
||||
'line_items' => $data['line_items'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a single order output for response.
|
||||
*
|
||||
|
@ -148,35 +190,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
|
|||
return new WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 );
|
||||
}
|
||||
|
||||
$data = $object->get_data();
|
||||
$format_decimal = array( 'amount' );
|
||||
$format_date = array( 'date_created' );
|
||||
$format_line_items = array( 'line_items' );
|
||||
|
||||
// Format decimal values.
|
||||
foreach ( $format_decimal as $key ) {
|
||||
$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Format line items.
|
||||
foreach ( $format_line_items as $key ) {
|
||||
$data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) );
|
||||
}
|
||||
|
||||
// Unset unwanted data.
|
||||
unset(
|
||||
$data['parent_id'], $data['status'], $data['currency'], $data['prices_include_tax'],
|
||||
$data['version'], $data['date_modified'], $data['discount_total'], $data['discount_tax'],
|
||||
$data['shipping_total'], $data['shipping_tax'], $data['cart_tax'], $data['cart_total'],
|
||||
$data['total'], $data['total_tax'], $data['tax_lines'], $data['shipping_lines'],
|
||||
$data['fee_lines'], $data['coupon_lines']
|
||||
);
|
||||
|
||||
$data = $this->get_formatted_item_data( $object );
|
||||
$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 +350,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',
|
||||
|
|
|
@ -185,16 +185,14 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Prepare a single order output for response.
|
||||
* Get formatted item data.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WC_Data $object Object data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
* @param WC_Data $object WC_Data instance.
|
||||
* @return array
|
||||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$this->request = $request;
|
||||
$data = array_merge( array( 'id' => $object->get_id() ), $object->get_data() );
|
||||
protected function get_formatted_item_data( $object ) {
|
||||
$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 +204,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,10 +227,66 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$response = rest_ensure_response( $data );
|
||||
return array(
|
||||
'id' => $object->get_id(),
|
||||
'parent_id' => $data['parent_id'],
|
||||
'number' => $data['number'],
|
||||
'order_key' => $data['order_key'],
|
||||
'created_via' => $data['created_via'],
|
||||
'version' => $data['version'],
|
||||
'status' => $data['status'],
|
||||
'currency' => $data['currency'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'discount_total' => $data['discount_total'],
|
||||
'discount_tax' => $data['discount_tax'],
|
||||
'shipping_total' => $data['shipping_total'],
|
||||
'shipping_tax' => $data['shipping_tax'],
|
||||
'cart_tax' => $data['cart_tax'],
|
||||
'total' => $data['total'],
|
||||
'total_tax' => $data['total_tax'],
|
||||
'prices_include_tax' => $data['prices_include_tax'],
|
||||
'customer_id' => $data['customer_id'],
|
||||
'customer_ip_address' => $data['customer_ip_address'],
|
||||
'customer_user_agent' => $data['customer_user_agent'],
|
||||
'customer_note' => $data['customer_note'],
|
||||
'billing' => $data['billing'],
|
||||
'shipping' => $data['shipping'],
|
||||
'payment_method' => $data['payment_method'],
|
||||
'payment_method_title' => $data['payment_method_title'],
|
||||
'transaction_id' => $data['transaction_id'],
|
||||
'date_paid' => $data['date_paid'],
|
||||
'date_paid_gmt' => $data['date_paid_gmt'],
|
||||
'date_completed' => $data['date_completed'],
|
||||
'date_completed_gmt' => $data['date_completed_gmt'],
|
||||
'cart_hash' => $data['cart_hash'],
|
||||
'meta_data' => $data['meta_data'],
|
||||
'line_items' => $data['line_items'],
|
||||
'tax_lines' => $data['tax_lines'],
|
||||
'shipping_lines' => $data['shipping_lines'],
|
||||
'fee_lines' => $data['fee_lines'],
|
||||
'coupon_lines' => $data['coupon_lines'],
|
||||
'refunds' => $data['refunds'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a single order output for response.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WC_Data $object Object data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$this->request = $request;
|
||||
$data = $this->get_formatted_item_data( $object );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$response = rest_ensure_response( $data );
|
||||
$response->add_links( $this->prepare_links( $object, $request ) );
|
||||
|
||||
/**
|
||||
|
@ -744,6 +800,30 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'number' => array(
|
||||
'description' => __( 'Order number.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'order_key' => array(
|
||||
'description' => __( 'Order key.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'created_via' => array(
|
||||
'description' => __( 'Shows where the order was created.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'version' => array(
|
||||
'description' => __( 'Version of WooCommerce when the order was made.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __( 'Order status.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
@ -758,30 +838,30 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'enum' => array_keys( get_woocommerce_currencies() ),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'version' => array(
|
||||
'description' => __( 'Version of WooCommerce when the order was made.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'prices_include_tax' => array(
|
||||
'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'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',
|
||||
|
@ -824,18 +904,35 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'prices_include_tax' => array(
|
||||
'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'customer_id' => array(
|
||||
'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'default' => 0,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'order_key' => array(
|
||||
'description' => __( 'Order key.', 'woocommerce' ),
|
||||
'customer_ip_address' => array(
|
||||
'description' => __( "Customer's IP address.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'customer_user_agent' => array(
|
||||
'description' => __( 'User agent of the customer.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'customer_note' => array(
|
||||
'description' => __( 'Note left by customer during checkout.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'billing' => array(
|
||||
'description' => __( 'Billing address.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
|
@ -966,47 +1063,32 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'customer_ip_address' => array(
|
||||
'description' => __( "Customer's IP address.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'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,
|
||||
),
|
||||
'customer_user_agent' => array(
|
||||
'description' => __( 'User agent of the customer.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'date_paid_gmt' => array(
|
||||
'description' => __( "The date the order has been paid, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'created_via' => array(
|
||||
'description' => __( 'Shows where the order was created.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'customer_note' => array(
|
||||
'description' => __( 'Note left by customer during checkout.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_completed' => array(
|
||||
'description' => __( "The date the order was completed, in the site's timezone.", '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' ),
|
||||
'date_completed_gmt' => array(
|
||||
'description' => __( "The date the order was completed, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'cart_hash' => array(
|
||||
'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'number' => array(
|
||||
'description' => __( 'Order number.', 'woocommerce' ),
|
||||
'cart_hash' => array(
|
||||
'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
|
|
@ -153,45 +153,49 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
|
|||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$data = array(
|
||||
'id' => $object->get_id(),
|
||||
'date_created' => wc_rest_prepare_date_response( $object->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified() ),
|
||||
'description' => $object->get_description(),
|
||||
'permalink' => $object->get_permalink(),
|
||||
'sku' => $object->get_sku(),
|
||||
'price' => $object->get_price(),
|
||||
'regular_price' => $object->get_regular_price(),
|
||||
'sale_price' => $object->get_sale_price(),
|
||||
'date_on_sale_from' => $object->get_date_on_sale_from() ? date( 'Y-m-d', $object->get_date_on_sale_from() ) : '',
|
||||
'date_on_sale_to' => $object->get_date_on_sale_to() ? date( 'Y-m-d', $object->get_date_on_sale_to() ) : '',
|
||||
'on_sale' => $object->is_on_sale(),
|
||||
'visible' => $object->is_visible(),
|
||||
'purchasable' => $object->is_purchasable(),
|
||||
'virtual' => $object->is_virtual(),
|
||||
'downloadable' => $object->is_downloadable(),
|
||||
'downloads' => $this->get_downloads( $object ),
|
||||
'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
|
||||
'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
|
||||
'tax_status' => $object->get_tax_status(),
|
||||
'tax_class' => $object->get_tax_class(),
|
||||
'manage_stock' => $object->managing_stock(),
|
||||
'stock_quantity' => $object->get_stock_quantity(),
|
||||
'in_stock' => $object->is_in_stock(),
|
||||
'backorders' => $object->get_backorders(),
|
||||
'backorders_allowed' => $object->backorders_allowed(),
|
||||
'backordered' => $object->is_on_backorder(),
|
||||
'weight' => $object->get_weight(),
|
||||
'dimensions' => array(
|
||||
'length' => $object->get_length(),
|
||||
'width' => $object->get_width(),
|
||||
'height' => $object->get_height(),
|
||||
'id' => $object->get_id(),
|
||||
'date_created' => wc_rest_prepare_date_response( $object->get_date_created(), false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified(), false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified() ),
|
||||
'description' => $object->get_description(),
|
||||
'permalink' => $object->get_permalink(),
|
||||
'sku' => $object->get_sku(),
|
||||
'price' => $object->get_price(),
|
||||
'regular_price' => $object->get_regular_price(),
|
||||
'sale_price' => $object->get_sale_price(),
|
||||
'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ),
|
||||
'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ),
|
||||
'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ),
|
||||
'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ),
|
||||
'on_sale' => $object->is_on_sale(),
|
||||
'visible' => $object->is_visible(),
|
||||
'purchasable' => $object->is_purchasable(),
|
||||
'virtual' => $object->is_virtual(),
|
||||
'downloadable' => $object->is_downloadable(),
|
||||
'downloads' => $this->get_downloads( $object ),
|
||||
'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
|
||||
'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
|
||||
'tax_status' => $object->get_tax_status(),
|
||||
'tax_class' => $object->get_tax_class(),
|
||||
'manage_stock' => $object->managing_stock(),
|
||||
'stock_quantity' => $object->get_stock_quantity(),
|
||||
'in_stock' => $object->is_in_stock(),
|
||||
'backorders' => $object->get_backorders(),
|
||||
'backorders_allowed' => $object->backorders_allowed(),
|
||||
'backordered' => $object->is_on_backorder(),
|
||||
'weight' => $object->get_weight(),
|
||||
'dimensions' => array(
|
||||
'length' => $object->get_length(),
|
||||
'width' => $object->get_width(),
|
||||
'height' => $object->get_height(),
|
||||
),
|
||||
'shipping_class' => $object->get_shipping_class(),
|
||||
'shipping_class_id' => $object->get_shipping_class_id(),
|
||||
'image' => $this->get_images( $object ),
|
||||
'attributes' => $this->get_attributes( $object ),
|
||||
'menu_order' => $object->get_menu_order(),
|
||||
'meta_data' => $object->get_meta_data(),
|
||||
'shipping_class' => $object->get_shipping_class(),
|
||||
'shipping_class_id' => $object->get_shipping_class_id(),
|
||||
'image' => $this->get_images( $object ),
|
||||
'attributes' => $this->get_attributes( $object ),
|
||||
'menu_order' => $object->get_menu_order(),
|
||||
'meta_data' => $object->get_meta_data(),
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
|
@ -338,10 +342,18 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
|
|||
$variation->set_date_on_sale_from( $request['date_on_sale_from'] );
|
||||
}
|
||||
|
||||
if ( isset( $request['date_on_sale_from_gmt'] ) ) {
|
||||
$variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null );
|
||||
}
|
||||
|
||||
if ( isset( $request['date_on_sale_to'] ) ) {
|
||||
$variation->set_date_on_sale_to( $request['date_on_sale_to'] );
|
||||
}
|
||||
|
||||
if ( isset( $request['date_on_sale_to_gmt'] ) ) {
|
||||
$variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null );
|
||||
}
|
||||
|
||||
// Tax class.
|
||||
if ( isset( $request['tax_class'] ) ) {
|
||||
$variation->set_tax_class( $request['tax_class'] );
|
||||
|
@ -632,13 +644,23 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller
|
|||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_from' => array(
|
||||
'description' => __( 'Start date of sale price.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_from_gmt' => array(
|
||||
'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_to' => array(
|
||||
'description' => __( 'End data of sale price.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_to_gmt' => array(
|
||||
'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'on_sale' => array(
|
||||
|
|
|
@ -369,26 +369,30 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
}
|
||||
|
||||
$images[] = array(
|
||||
'id' => (int) $attachment_id,
|
||||
'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date_gmt ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified_gmt ),
|
||||
'src' => current( $attachment ),
|
||||
'name' => get_the_title( $attachment_id ),
|
||||
'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
|
||||
'position' => (int) $position,
|
||||
'id' => (int) $attachment_id,
|
||||
'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified, false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ),
|
||||
'src' => current( $attachment ),
|
||||
'name' => get_the_title( $attachment_id ),
|
||||
'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
|
||||
'position' => (int) $position,
|
||||
);
|
||||
}
|
||||
|
||||
// Set a placeholder image if the product has no images set.
|
||||
if ( empty( $images ) ) {
|
||||
$images[] = array(
|
||||
'id' => 0,
|
||||
'date_created' => wc_rest_prepare_date_response( current_time( 'mysql' ) ), // Default to now.
|
||||
'date_modified' => wc_rest_prepare_date_response( current_time( 'mysql' ) ),
|
||||
'src' => wc_placeholder_img_src(),
|
||||
'name' => __( 'Placeholder', 'woocommerce' ),
|
||||
'alt' => __( 'Placeholder', 'woocommerce' ),
|
||||
'position' => 0,
|
||||
'id' => 0,
|
||||
'date_created' => wc_rest_prepare_date_response( current_time( 'mysql' ), false ), // Default to now.
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ), // Default to now.
|
||||
'date_modified' => wc_rest_prepare_date_response( current_time( 'mysql' ), false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( current_time( 'timestamp', true ) ),
|
||||
'src' => wc_placeholder_img_src(),
|
||||
'name' => __( 'Placeholder', 'woocommerce' ),
|
||||
'alt' => __( 'Placeholder', 'woocommerce' ),
|
||||
'position' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -528,8 +532,10 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'name' => $product->get_name(),
|
||||
'slug' => $product->get_slug(),
|
||||
'permalink' => $product->get_permalink(),
|
||||
'date_created' => wc_rest_prepare_date_response( $product->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $product->get_date_modified() ),
|
||||
'date_created' => wc_rest_prepare_date_response( $product->get_date_created(), false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( $product->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $product->get_date_modified(), false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( $product->get_date_modified() ),
|
||||
'type' => $product->get_type(),
|
||||
'status' => $product->get_status(),
|
||||
'featured' => $product->is_featured(),
|
||||
|
@ -540,8 +546,10 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'price' => $product->get_price(),
|
||||
'regular_price' => $product->get_regular_price(),
|
||||
'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '',
|
||||
'date_on_sale_from' => $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from() ) : '',
|
||||
'date_on_sale_to' => $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to() ) : '',
|
||||
'date_on_sale_from' => wc_rest_prepare_date_response( $product->get_date_on_sale_from(), false ),
|
||||
'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $product->get_date_on_sale_from() ),
|
||||
'date_on_sale_to' => wc_rest_prepare_date_response( $product->get_date_on_sale_to(), false ),
|
||||
'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $product->get_date_on_sale_to() ),
|
||||
'price_html' => $product->get_price_html(),
|
||||
'on_sale' => $product->is_on_sale(),
|
||||
'purchasable' => $product->is_purchasable(),
|
||||
|
@ -811,9 +819,17 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
$product->set_date_on_sale_from( $request['date_on_sale_from'] );
|
||||
}
|
||||
|
||||
if ( isset( $request['date_on_sale_from_gmt'] ) ) {
|
||||
$product->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null );
|
||||
}
|
||||
|
||||
if ( isset( $request['date_on_sale_to'] ) ) {
|
||||
$product->set_date_on_sale_to( $request['date_on_sale_to'] );
|
||||
}
|
||||
|
||||
if ( isset( $request['date_on_sale_to_gmt'] ) ) {
|
||||
$product->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null );
|
||||
}
|
||||
}
|
||||
|
||||
// Product parent ID for groups.
|
||||
|
@ -1354,12 +1370,24 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the product was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the product 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 product was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __( 'Product type.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
@ -1419,13 +1447,23 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_from' => array(
|
||||
'description' => __( 'Start date of sale price.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_from_gmt' => array(
|
||||
'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_to' => array(
|
||||
'description' => __( 'End data of sale price.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_on_sale_to_gmt' => array(
|
||||
'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'price_html' => array(
|
||||
|
@ -1753,12 +1791,24 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the image was created, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the image 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 image was last modified, as GMT.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'src' => array(
|
||||
'description' => __( 'Image URL.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
|
|
@ -111,8 +111,8 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
'id' => $coupon->get_id(),
|
||||
'code' => $coupon->get_code(),
|
||||
'type' => $coupon->get_discount_type(),
|
||||
'created_at' => $this->server->format_datetime( $coupon->get_date_created(), false, true ),
|
||||
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $coupon->get_date_created() ? $coupon->get_date_created()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified() ? $coupon->get_date_modified()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'amount' => wc_format_decimal( $coupon->get_amount(), 2 ),
|
||||
'individual_use' => $coupon->get_individual_use(),
|
||||
'product_ids' => array_map( 'absint', (array) $coupon->get_product_ids() ),
|
||||
|
@ -121,7 +121,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null,
|
||||
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
|
||||
'usage_count' => (int) $coupon->get_usage_count(),
|
||||
'expiry_date' => $this->server->format_datetime( $coupon->get_date_expires(), false, true ),
|
||||
'expiry_date' => $this->server->format_datetime( $coupon->get_date_expires() ? $coupon->get_date_expires()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'enable_free_shipping' => $coupon->get_free_shipping(),
|
||||
'product_category_ids' => array_map( 'absint', (array) $coupon->get_product_categories() ),
|
||||
'exclude_product_category_ids' => array_map( 'absint', (array) $coupon->get_excluded_product_categories() ),
|
||||
|
|
|
@ -132,13 +132,13 @@ class WC_API_Customers extends WC_API_Resource {
|
|||
$last_order = $customer->get_last_order();
|
||||
$customer_data = array(
|
||||
'id' => $customer->get_id(),
|
||||
'created_at' => $this->server->format_datetime( $customer->get_date_created(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $customer->get_date_created() ? $customer->get_date_created()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'email' => $customer->get_email(),
|
||||
'first_name' => $customer->get_first_name(),
|
||||
'last_name' => $customer->get_last_name(),
|
||||
'username' => $customer->get_username(),
|
||||
'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null,
|
||||
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->get_date_created(), false, true ) : null,
|
||||
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->get_date_created() ? $last_order->get_date_created()->getTimestamp() : 0 ) : null, // API gives UTC times.
|
||||
'orders_count' => $customer->get_order_count(),
|
||||
'total_spent' => wc_format_decimal( $customer->get_total_spent(), 2 ),
|
||||
'avatar_url' => $customer->get_avatar_url(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -121,8 +121,8 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
'id' => $coupon->get_id(),
|
||||
'code' => $coupon->get_code(),
|
||||
'type' => $coupon->get_discount_type(),
|
||||
'created_at' => $this->server->format_datetime( $coupon->get_date_created(), false, true ),
|
||||
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $coupon->get_date_created() ? $coupon->get_date_created()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified() ? $coupon->get_date_modified()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'amount' => wc_format_decimal( $coupon->get_amount(), 2 ),
|
||||
'individual_use' => $coupon->get_individual_use(),
|
||||
'product_ids' => array_map( 'absint', (array) $coupon->get_product_ids() ),
|
||||
|
@ -131,7 +131,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null,
|
||||
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
|
||||
'usage_count' => (int) $coupon->get_usage_count(),
|
||||
'expiry_date' => $coupon->get_date_expires() ? $this->server->format_datetime( $coupon->get_date_expires() ) : null,
|
||||
'expiry_date' => $coupon->get_date_expires() ? $this->server->format_datetime( $coupon->get_date_expires()->getTimestamp() ) : null, // API gives UTC times.
|
||||
'enable_free_shipping' => $coupon->get_free_shipping(),
|
||||
'product_category_ids' => array_map( 'absint', (array) $coupon->get_product_categories() ),
|
||||
'exclude_product_category_ids' => array_map( 'absint', (array) $coupon->get_excluded_product_categories() ),
|
||||
|
@ -283,6 +283,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
update_post_meta( $id, 'limit_usage_to_x_items', absint( $coupon_data['limit_usage_to_x_items'] ) );
|
||||
update_post_meta( $id, 'usage_count', absint( $coupon_data['usage_count'] ) );
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'free_shipping', ( true === $coupon_data['enable_free_shipping'] ) ? 'yes' : 'no' );
|
||||
update_post_meta( $id, 'product_categories', array_filter( array_map( 'intval', $coupon_data['product_category_ids'] ) ) );
|
||||
update_post_meta( $id, 'exclude_product_categories', array_filter( array_map( 'intval', $coupon_data['exclude_product_category_ids'] ) ) );
|
||||
|
@ -393,6 +394,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
|
||||
if ( isset( $data['expiry_date'] ) ) {
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ), true ) );
|
||||
}
|
||||
|
||||
if ( isset( $data['enable_free_shipping'] ) ) {
|
||||
|
@ -457,10 +459,15 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
*
|
||||
* @since 2.3.0
|
||||
* @param string $expiry_date
|
||||
* @return string
|
||||
* @param bool $as_timestamp (default: false)
|
||||
* @return string|int
|
||||
*/
|
||||
protected function get_coupon_expiry_date( $expiry_date ) {
|
||||
protected function get_coupon_expiry_date( $expiry_date, $as_timestamp = false ) {
|
||||
if ( '' != $expiry_date ) {
|
||||
if ( $as_timestamp ) {
|
||||
return strtotime( $expiry_date );
|
||||
}
|
||||
|
||||
return date( 'Y-m-d', strtotime( $expiry_date ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -150,14 +150,14 @@ class WC_API_Customers extends WC_API_Resource {
|
|||
$last_order = $customer->get_last_order();
|
||||
$customer_data = array(
|
||||
'id' => $customer->get_id(),
|
||||
'created_at' => $this->server->format_datetime( $customer->get_date_created(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $customer->get_date_created() ? $customer->get_date_created()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'email' => $customer->get_email(),
|
||||
'first_name' => $customer->get_first_name(),
|
||||
'last_name' => $customer->get_last_name(),
|
||||
'username' => $customer->get_username(),
|
||||
'role' => $customer->get_role(),
|
||||
'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null,
|
||||
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->get_date_created(), false, true ) : null,
|
||||
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->get_date_created() ? $last_order->get_date_created()->getTimestamp() : 0 ) : null, // API gives UTC times.
|
||||
'orders_count' => $customer->get_order_count(),
|
||||
'total_spent' => wc_format_decimal( $customer->get_total_spent(), 2 ),
|
||||
'avatar_url' => $customer->get_avatar_url(),
|
||||
|
@ -513,8 +513,17 @@ class WC_API_Customers extends WC_API_Resource {
|
|||
$_downloads = wc_get_customer_available_downloads( $id );
|
||||
|
||||
foreach ( $_downloads as $key => $download ) {
|
||||
$downloads[ $key ] = $download;
|
||||
$downloads[ $key ]['access_expires'] = $this->server->format_datetime( $downloads[ $key ]['access_expires'] );
|
||||
$downloads[] = array(
|
||||
'download_url' => $download['download_url'],
|
||||
'download_id' => $download['download_id'],
|
||||
'product_id' => $download['product_id'],
|
||||
'download_name' => $download['download_name'],
|
||||
'order_id' => $download['order_id'],
|
||||
'order_key' => $download['order_key'],
|
||||
'downloads_remaining' => $download['downloads_remaining'],
|
||||
'access_expires' => $download['access_expires'] ? $this->server->format_datetime( $download['access_expires'] ) : null,
|
||||
'file' => $download['file'],
|
||||
);
|
||||
}
|
||||
|
||||
return array( 'downloads' => apply_filters( 'woocommerce_api_customer_downloads_response', $downloads, $id, $fields, $this->server ) );
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1049,17 +1049,17 @@ class WC_API_Products extends WC_API_Resource {
|
|||
if ( isset( $data['sale_price_dates_from'] ) ) {
|
||||
$date_from = $data['sale_price_dates_from'];
|
||||
} else {
|
||||
$date_from = ( $product->get_date_on_sale_from() ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
$date_from = $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( isset( $data['sale_price_dates_to'] ) ) {
|
||||
$date_to = $data['sale_price_dates_to'];
|
||||
} else {
|
||||
$date_to = ( $product->get_date_on_sale_to() ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
$date_to = $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( $date_to && ! $date_from ) {
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$product->set_date_on_sale_to( $date_to );
|
||||
|
|
|
@ -121,8 +121,8 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
'id' => $coupon->get_id(),
|
||||
'code' => $coupon->get_code(),
|
||||
'type' => $coupon->get_discount_type(),
|
||||
'created_at' => $this->server->format_datetime( $coupon->get_date_created(), false, true ),
|
||||
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified(), false, true ),
|
||||
'created_at' => $this->server->format_datetime( $coupon->get_date_created() ? $coupon->get_date_created()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified() ? $coupon->get_date_modified()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'amount' => wc_format_decimal( $coupon->get_amount(), 2 ),
|
||||
'individual_use' => $coupon->get_individual_use(),
|
||||
'product_ids' => array_map( 'absint', (array) $coupon->get_product_ids() ),
|
||||
|
@ -131,7 +131,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
'usage_limit_per_user' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : null,
|
||||
'limit_usage_to_x_items' => (int) $coupon->get_limit_usage_to_x_items(),
|
||||
'usage_count' => (int) $coupon->get_usage_count(),
|
||||
'expiry_date' => $coupon->get_date_expires() ? $this->server->format_datetime( $coupon->get_date_expires(), false, true ) : null,
|
||||
'expiry_date' => $coupon->get_date_expires() ? $this->server->format_datetime( $coupon->get_date_expires()->getTimestamp() ) : null, // API gives UTC times.
|
||||
'enable_free_shipping' => $coupon->get_free_shipping(),
|
||||
'product_category_ids' => array_map( 'absint', (array) $coupon->get_product_categories() ),
|
||||
'exclude_product_category_ids' => array_map( 'absint', (array) $coupon->get_excluded_product_categories() ),
|
||||
|
@ -283,6 +283,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
update_post_meta( $id, 'limit_usage_to_x_items', absint( $coupon_data['limit_usage_to_x_items'] ) );
|
||||
update_post_meta( $id, 'usage_count', absint( $coupon_data['usage_count'] ) );
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $coupon_data['expiry_date'] ), true ) );
|
||||
update_post_meta( $id, 'free_shipping', ( true === $coupon_data['enable_free_shipping'] ) ? 'yes' : 'no' );
|
||||
update_post_meta( $id, 'product_categories', array_filter( array_map( 'intval', $coupon_data['product_category_ids'] ) ) );
|
||||
update_post_meta( $id, 'exclude_product_categories', array_filter( array_map( 'intval', $coupon_data['exclude_product_category_ids'] ) ) );
|
||||
|
@ -393,6 +394,7 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
|
||||
if ( isset( $data['expiry_date'] ) ) {
|
||||
update_post_meta( $id, 'expiry_date', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ) ) );
|
||||
update_post_meta( $id, 'date_expires', $this->get_coupon_expiry_date( wc_clean( $data['expiry_date'] ), true ) );
|
||||
}
|
||||
|
||||
if ( isset( $data['enable_free_shipping'] ) ) {
|
||||
|
@ -457,10 +459,15 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
*
|
||||
* @since 2.3.0
|
||||
* @param string $expiry_date
|
||||
* @return string
|
||||
* @param bool $as_timestamp (default: false)
|
||||
* @return string|int
|
||||
*/
|
||||
protected function get_coupon_expiry_date( $expiry_date ) {
|
||||
protected function get_coupon_expiry_date( $expiry_date, $as_timestamp = false ) {
|
||||
if ( '' != $expiry_date ) {
|
||||
if ( $as_timestamp ) {
|
||||
return strtotime( $expiry_date );
|
||||
}
|
||||
|
||||
return date( 'Y-m-d', strtotime( $expiry_date ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -150,15 +150,15 @@ class WC_API_Customers extends WC_API_Resource {
|
|||
$last_order = $customer->get_last_order();
|
||||
$customer_data = array(
|
||||
'id' => $customer->get_id(),
|
||||
'created_at' => $this->server->format_datetime( $customer->get_date_created() ),
|
||||
'last_update' => $this->server->format_datetime( $customer->get_date_modified() ),
|
||||
'created_at' => $this->server->format_datetime( $customer->get_date_created() ? $customer->get_date_created()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'last_update' => $this->server->format_datetime( $customer->get_date_modified() ? $customer->get_date_modified()->getTimestamp() : 0 ), // API gives UTC times.
|
||||
'email' => $customer->get_email(),
|
||||
'first_name' => $customer->get_first_name(),
|
||||
'last_name' => $customer->get_last_name(),
|
||||
'username' => $customer->get_username(),
|
||||
'role' => $customer->get_role(),
|
||||
'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null,
|
||||
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->get_date_created() ) : null,
|
||||
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->get_date_created() ? $last_order->get_date_created()->getTimestamp() : 0 ) : null, // API gives UTC times.
|
||||
'orders_count' => $customer->get_order_count(),
|
||||
'total_spent' => wc_format_decimal( $customer->get_total_spent(), 2 ),
|
||||
'avatar_url' => $customer->get_avatar_url(),
|
||||
|
@ -498,8 +498,17 @@ class WC_API_Customers extends WC_API_Resource {
|
|||
$_downloads = wc_get_customer_available_downloads( $id );
|
||||
|
||||
foreach ( $_downloads as $key => $download ) {
|
||||
$downloads[ $key ] = $download;
|
||||
$downloads[ $key ]['access_expires'] = $this->server->format_datetime( $downloads[ $key ]['access_expires'] );
|
||||
$downloads[] = array(
|
||||
'download_url' => $download['download_url'],
|
||||
'download_id' => $download['download_id'],
|
||||
'product_id' => $download['product_id'],
|
||||
'download_name' => $download['download_name'],
|
||||
'order_id' => $download['order_id'],
|
||||
'order_key' => $download['order_key'],
|
||||
'downloads_remaining' => $download['downloads_remaining'],
|
||||
'access_expires' => $download['access_expires'] ? $this->server->format_datetime( $download['access_expires'] ) : null,
|
||||
'file' => $download['file'],
|
||||
);
|
||||
}
|
||||
|
||||
return array( 'downloads' => apply_filters( 'woocommerce_api_customer_downloads_response', $downloads, $id, $fields, $this->server ) );
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1534,17 +1534,17 @@ class WC_API_Products extends WC_API_Resource {
|
|||
if ( isset( $data['sale_price_dates_from'] ) ) {
|
||||
$date_from = $data['sale_price_dates_from'];
|
||||
} else {
|
||||
$date_from = ( $product->get_date_on_sale_from() ) ? date( 'Y-m-d', $date_from ) : '';
|
||||
$date_from = $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( isset( $data['sale_price_dates_to'] ) ) {
|
||||
$date_to = $data['sale_price_dates_to'];
|
||||
} else {
|
||||
$date_to = ( $product->get_date_on_sale_to() ) ? date( 'Y-m-d', $date_to ) : '';
|
||||
$date_to = $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() ) : '';
|
||||
}
|
||||
|
||||
if ( $date_to && ! $date_from ) {
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
|
||||
$date_from = strtotime( 'NOW', current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$product->set_date_on_sale_to( $date_to );
|
||||
|
|
|
@ -150,9 +150,10 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_Controller {
|
|||
$coupon = new WC_Coupon( (int) $post->ID );
|
||||
$_data = $coupon->get_data();
|
||||
|
||||
$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
|
||||
$format_date = array( 'date_created', 'date_modified', 'date_expires' );
|
||||
$format_null = array( 'usage_limit', 'usage_limit_per_user' );
|
||||
$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
|
||||
$format_date = array( 'date_created', 'date_modified' );
|
||||
$format_date_utc = array( 'date_expires' );
|
||||
$format_null = array( 'usage_limit', 'usage_limit_per_user' );
|
||||
|
||||
// Format decimal values.
|
||||
foreach ( $format_decimal as $key ) {
|
||||
|
@ -161,7 +162,10 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_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 ] ) ) ) : null;
|
||||
$_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ], false ) : null;
|
||||
}
|
||||
foreach( $format_date_utc as $key ) {
|
||||
$_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ] ) : null;
|
||||
}
|
||||
|
||||
// Format null values.
|
||||
|
@ -270,6 +274,9 @@ class WC_REST_Coupons_V1_Controller extends WC_REST_Posts_Controller {
|
|||
case 'description' :
|
||||
$coupon->set_description( wp_filter_post_kses( $value ) );
|
||||
break;
|
||||
case 'expiry_date' :
|
||||
$coupon->set_date_expires( $value );
|
||||
break;
|
||||
default :
|
||||
if ( is_callable( array( $coupon, "set_{$key}" ) ) ) {
|
||||
$coupon->{"set_{$key}"}( $value );
|
||||
|
|
|
@ -520,7 +520,7 @@ class WC_REST_Customers_V1_Controller extends WC_REST_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 ] ) ) ) : null;
|
||||
$_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ] ) : null; // v1 API used UTC.
|
||||
}
|
||||
|
||||
$data = array(
|
||||
|
@ -533,7 +533,7 @@ class WC_REST_Customers_V1_Controller extends WC_REST_Controller {
|
|||
'username' => $_data['username'],
|
||||
'last_order' => array(
|
||||
'id' => is_object( $last_order ) ? $last_order->get_id() : null,
|
||||
'date' => is_object( $last_order ) ? wc_rest_prepare_date_response( get_gmt_from_date( date( 'Y-m-d H:i:s', $last_order->get_date_created() ) ) ) : null,
|
||||
'date' => is_object( $last_order ) ? wc_rest_prepare_date_response( $last_order->get_date_created() ) : null, // v1 API used UTC.
|
||||
),
|
||||
'orders_count' => $customer->get_order_count(),
|
||||
'total_spent' => $customer->get_total_spent(),
|
||||
|
@ -633,13 +633,13 @@ class WC_REST_Customers_V1_Controller extends WC_REST_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the customer was created, in the site's timezone.", 'woocommerce' ),
|
||||
'description' => __( 'The date the customer was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the customer was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
@ -692,7 +692,7 @@ class WC_REST_Customers_V1_Controller extends WC_REST_Controller {
|
|||
'readonly' => true,
|
||||
),
|
||||
'date' => array(
|
||||
'description' => __( 'UTC DateTime of the customer last order.', 'woocommerce' ),
|
||||
'description' => __( 'The date of the customer last order, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -475,8 +475,8 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'price' => $product->get_price(),
|
||||
'regular_price' => $product->get_regular_price(),
|
||||
'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '',
|
||||
'date_on_sale_from' => $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from() ) : '',
|
||||
'date_on_sale_to' => $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to() ) : '',
|
||||
'date_on_sale_from' => $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from()->getTimestamp() ) : '',
|
||||
'date_on_sale_to' => $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() ) : '',
|
||||
'price_html' => $product->get_price_html(),
|
||||
'on_sale' => $product->is_on_sale(),
|
||||
'purchasable' => $product->is_purchasable(),
|
||||
|
@ -553,8 +553,8 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
|
|||
'price' => $variation->get_price(),
|
||||
'regular_price' => $variation->get_regular_price(),
|
||||
'sale_price' => $variation->get_sale_price(),
|
||||
'date_on_sale_from' => $variation->get_date_on_sale_from() ? date( 'Y-m-d', $variation->get_date_on_sale_from() ) : '',
|
||||
'date_on_sale_to' => $variation->get_date_on_sale_to() ? date( 'Y-m-d', $variation->get_date_on_sale_to() ) : '',
|
||||
'date_on_sale_from' => $variation->get_date_on_sale_from() ? date( 'Y-m-d', $variation->get_date_on_sale_from()->getTimestamp() ) : '',
|
||||
'date_on_sale_to' => $variation->get_date_on_sale_to() ? date( 'Y-m-d', $variation->get_date_on_sale_to()->getTimestamp() ) : '',
|
||||
'on_sale' => $variation->is_on_sale(),
|
||||
'purchasable' => $variation->is_purchasable(),
|
||||
'visible' => $variation->is_visible(),
|
||||
|
|
|
@ -729,6 +729,10 @@ class WC_AJAX {
|
|||
wc_deprecated_function( 'The woocommerce_found_customer_details filter', '2.7', 'woocommerce_found_customer_details' );
|
||||
}
|
||||
|
||||
$data = $customer->get_data();
|
||||
$data['date_created'] = $data['date_created'] ? $data['date_created']->getTimestamp() : null;
|
||||
$data['date_modified'] = $data['date_modified'] ? $data['date_modified']->getTimestamp() : null;
|
||||
|
||||
$customer_data = apply_filters( 'woocommerce_ajax_get_customer_details', $customer->get_data(), $customer, $user_id );
|
||||
wp_send_json( $customer_data );
|
||||
}
|
||||
|
|
|
@ -26,11 +26,11 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
protected $data = array(
|
||||
'code' => '',
|
||||
'amount' => 0,
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'date_created' => null,
|
||||
'date_modified' => null,
|
||||
'date_expires' => null,
|
||||
'discount_type' => 'fixed_cart',
|
||||
'description' => '',
|
||||
'date_expires' => '',
|
||||
'usage_count' => 0,
|
||||
'individual_use' => false,
|
||||
'product_ids' => array(),
|
||||
|
@ -172,7 +172,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
* Get coupon expiration date.
|
||||
* @since 2.7.0
|
||||
* @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_expires( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_expires', $context );
|
||||
|
@ -182,7 +182,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
* Get date_created
|
||||
* @since 2.7.0
|
||||
* @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_created( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_created', $context );
|
||||
|
@ -192,7 +192,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
* Get date_modified
|
||||
* @since 2.7.0
|
||||
* @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_modified( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_modified', $context );
|
||||
|
@ -467,31 +467,31 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
/**
|
||||
* Set expiration date.
|
||||
* @since 2.7.0
|
||||
* @param string $timestamp 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 there is no date.
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_date_expires( $timestamp ) {
|
||||
$this->set_prop( 'date_expires', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_expires( $date ) {
|
||||
$this->set_date_prop( 'date_expires', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_created
|
||||
* @since 2.7.0
|
||||
* @param string $timestamp 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 there is no date.
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_date_created( $timestamp ) {
|
||||
$this->set_prop( 'date_created', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_created( $date ) {
|
||||
$this->set_date_prop( 'date_created', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date_modified
|
||||
* @since 2.7.0
|
||||
* @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 there is no date.
|
||||
* @throws WC_Data_Exception
|
||||
*/
|
||||
public function set_date_modified( $timestamp ) {
|
||||
$this->set_prop( 'date_modified', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_modified( $date ) {
|
||||
$this->set_date_prop( 'date_modified', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -802,7 +802,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
* @throws Exception
|
||||
*/
|
||||
private function validate_expiry_date() {
|
||||
if ( $this->get_date_expires() && current_time( 'timestamp' ) > $this->get_date_expires() ) {
|
||||
if ( $this->get_date_expires() && current_time( 'timestamp', true ) > $this->get_date_expires()->getTimestamp() ) {
|
||||
throw new Exception( $error_code = self::E_WC_COUPON_EXPIRED );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ class WC_Customer_Download extends WC_Data implements ArrayAccess {
|
|||
'order_id' => 0,
|
||||
'order_key' => '',
|
||||
'downloads_remaining' => '',
|
||||
'access_granted' => '',
|
||||
'access_expires' => '',
|
||||
'access_granted' => null,
|
||||
'access_expires' => null,
|
||||
'download_count' => 0,
|
||||
);
|
||||
|
||||
|
@ -145,7 +145,7 @@ class WC_Customer_Download extends WC_Data implements ArrayAccess {
|
|||
* Get access_granted.
|
||||
*
|
||||
* @param string $context
|
||||
* @return integer
|
||||
* @return WC_DateTime|null Object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_access_granted( $context = 'view' ) {
|
||||
return $this->get_prop( 'access_granted', $context );
|
||||
|
@ -155,7 +155,7 @@ class WC_Customer_Download extends WC_Data implements ArrayAccess {
|
|||
* Get access_expires.
|
||||
*
|
||||
* @param string $context
|
||||
* @return integer
|
||||
* @return WC_DateTime|null Object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_access_expires( $context = 'view' ) {
|
||||
return $this->get_prop( 'access_expires', $context );
|
||||
|
@ -242,19 +242,19 @@ class WC_Customer_Download extends WC_Data implements ArrayAccess {
|
|||
/**
|
||||
* Get access_granted.
|
||||
*
|
||||
* @param int $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.
|
||||
*/
|
||||
public function set_access_granted( $timestamp ) {
|
||||
$this->set_prop( 'access_granted', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_access_granted( $date = null ) {
|
||||
$this->set_date_prop( 'access_granted', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get access_expires.
|
||||
*
|
||||
* @param int $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.
|
||||
*/
|
||||
public function set_access_expires( $timestamp ) {
|
||||
$this->set_prop( 'access_expires', is_numeric( $timestamp ) || is_null( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_access_expires( $date = null ) {
|
||||
$this->set_date_prop( 'access_expires', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,8 +22,8 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
* @var array
|
||||
*/
|
||||
protected $data = array(
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'date_created' => null,
|
||||
'date_modified' => null,
|
||||
'email' => '',
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
|
@ -398,7 +398,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
*
|
||||
* @since 2.7.0
|
||||
* @param string $context
|
||||
* @return integer
|
||||
* @return WC_DateTime|null object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_created( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_created', $context );
|
||||
|
@ -409,7 +409,7 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
*
|
||||
* @since 2.7.0
|
||||
* @param string $context
|
||||
* @return integer
|
||||
* @return WC_DateTime|null object if the date is set or null if there is no date.
|
||||
*/
|
||||
public function get_date_modified( $context = 'view' ) {
|
||||
return $this->get_prop( 'date_modified', $context );
|
||||
|
@ -740,23 +740,23 @@ class WC_Customer extends WC_Legacy_Customer {
|
|||
/**
|
||||
* Set the date this customer was last updated.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param integer $timestamp
|
||||
* @since 2.7.0
|
||||
* @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_modified( $timestamp ) {
|
||||
$this->set_prop( 'date_modified', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_created( $date = null ) {
|
||||
$this->set_date_prop( 'date_created', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date this customer was last updated.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param integer $timestamp
|
||||
* @since 2.7.0
|
||||
* @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_created( $timestamp ) {
|
||||
$this->set_prop( 'date_created', is_numeric( $timestamp ) ? $timestamp : strtotime( $timestamp ) );
|
||||
public function set_date_modified( $date = null ) {
|
||||
$this->set_date_prop( 'date_modified', $date );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* WC Wrapper for PHP DateTime.
|
||||
*
|
||||
* @class WC_DateTime
|
||||
* @since 2.7.0
|
||||
* @package WooCommerce/Classes
|
||||
* @category Class
|
||||
* @author WooThemes
|
||||
*/
|
||||
class WC_DateTime extends DateTime {
|
||||
|
||||
/**
|
||||
* Output an ISO 8601 date string in local timezone.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return string
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->format( DATE_ATOM );
|
||||
}
|
||||
|
||||
/**
|
||||
* Missing in PHP 5.2.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return int
|
||||
*/
|
||||
public function getTimestamp() {
|
||||
return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the timestamp with the WordPress timezone offset added or subtracted.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @return int
|
||||
*/
|
||||
public function getOffsetTimestamp() {
|
||||
return $this->getTimestamp() + $this->getOffset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a date based on the offset timestamp.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function date( $format ) {
|
||||
return gmdate( $format, $this->getOffsetTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a localised date based on offset timestamp. Wrapper for date_i18n function.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function date_i18n( $format = 'Y-m-d' ) {
|
||||
return date_i18n( $format, $this->getOffsetTimestamp() );
|
||||
}
|
||||
}
|
|
@ -111,7 +111,7 @@ class WC_Download_Handler {
|
|||
* @access private
|
||||
*/
|
||||
private static function check_download_expiry( $download ) {
|
||||
if ( $download->get_access_expires() > 0 && $download->get_access_expires() < strtotime( 'midnight', current_time( 'timestamp' ) ) ) {
|
||||
if ( ! is_null( $download->get_access_expires() ) && $download->get_access_expires()->getTimestamp() < strtotime( 'midnight', current_time( 'timestamp', true ) ) ) {
|
||||
self::download_error( __( 'Sorry, this download has expired', 'woocommerce' ), '', 403 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ class WC_Order extends WC_Abstract_Order {
|
|||
'currency' => '',
|
||||
'version' => '',
|
||||
'prices_include_tax' => false,
|
||||
'date_created' => '',
|
||||
'date_modified' => '',
|
||||
'date_created' => null,
|
||||
'date_modified' => null,
|
||||
'discount_total' => 0,
|
||||
'discount_tax' => 0,
|
||||
'shipping_total' => 0,
|
||||
|
@ -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();
|
||||
|
@ -269,7 +269,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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -715,7 +715,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 );
|
||||
|
@ -725,7 +725,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' ) {
|
||||
$date_paid = $this->get_prop( 'date_paid', $context );
|
||||
|
@ -1160,21 +1160,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();
|
||||
|
|
|
@ -50,12 +50,12 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
|||
*/
|
||||
public function create( &$order ) {
|
||||
$order->set_version( WC_VERSION );
|
||||
$order->set_date_created( current_time( 'timestamp' ) );
|
||||
$order->set_date_created( current_time( 'timestamp', true ) );
|
||||
$order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() );
|
||||
|
||||
$id = wp_insert_post( apply_filters( 'woocommerce_new_order_data', array(
|
||||
'post_date' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' ) ),
|
||||
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' ) ) ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
|
||||
'post_type' => $order->get_type( 'edit' ),
|
||||
'post_status' => 'wc-' . ( $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ) ),
|
||||
'ping_status' => 'closed',
|
||||
|
@ -89,10 +89,11 @@ 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,
|
||||
'date_modified' => $post_object->post_modified,
|
||||
'date_created' => strtotime( $post_object->post_date_gmt ),
|
||||
'date_modified' => strtotime( $post_object->post_modified_gmt ),
|
||||
'status' => $post_object->post_status,
|
||||
) );
|
||||
|
||||
$this->read_order_data( $order, $post_object );
|
||||
$order->read_meta_data();
|
||||
$order->set_object_read( true );
|
||||
|
@ -120,13 +121,13 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
|||
if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) {
|
||||
wp_update_post( array(
|
||||
'ID' => $order->get_id(),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' ) ),
|
||||
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' ) ) ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
|
||||
'post_status' => 'wc-' . ( $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ) ),
|
||||
'post_parent' => $order->get_parent_id(),
|
||||
'post_excerpt' => $this->get_post_excerpt( $order ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' ) ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? get_gmt_from_date( date( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' ) ) ) : current_time( 'mysql', 1 ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
|
||||
) );
|
||||
}
|
||||
$this->update_post_meta( $order );
|
||||
|
|
|
@ -28,6 +28,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
'discount_type',
|
||||
'coupon_amount',
|
||||
'expiry_date',
|
||||
'date_expires',
|
||||
'usage_count',
|
||||
'individual_use',
|
||||
'product_ids',
|
||||
|
@ -54,7 +55,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
* @param WC_Coupon
|
||||
*/
|
||||
public function create( &$coupon ) {
|
||||
$coupon->set_date_created( current_time( 'timestamp' ) );
|
||||
$coupon->set_date_created( current_time( 'timestamp', true ) );
|
||||
|
||||
$coupon_id = wp_insert_post( apply_filters( 'woocommerce_new_coupon_data', array(
|
||||
'post_type' => 'shop_coupon',
|
||||
|
@ -63,8 +64,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
'post_title' => $coupon->get_code(),
|
||||
'post_content' => '',
|
||||
'post_excerpt' => $coupon->get_description(),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $coupon->get_date_created() ),
|
||||
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $coupon->get_date_created() ) ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $coupon->get_date_created()->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => date( 'Y-m-d H:i:s', $coupon->get_date_created()->getTimestamp() ),
|
||||
) ), true );
|
||||
|
||||
if ( $coupon_id ) {
|
||||
|
@ -93,9 +94,9 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
$coupon->set_props( array(
|
||||
'code' => $post_object->post_title,
|
||||
'description' => $post_object->post_excerpt,
|
||||
'date_created' => $post_object->post_date,
|
||||
'date_modified' => $post_object->post_modified,
|
||||
'date_expires' => get_post_meta( $coupon_id, 'expiry_date', true ),
|
||||
'date_created' => strtotime( $post_object->post_date_gmt ),
|
||||
'date_modified' => strtotime( $post_object->post_modified_gmt ),
|
||||
'date_expires' => metadata_exists( 'post', $coupon_id, 'date_expires' ) ? get_post_meta( $coupon_id, 'date_expires', true ) : get_post_meta( $coupon_id, 'expiry_date', true ),
|
||||
'discount_type' => get_post_meta( $coupon_id, 'discount_type', true ),
|
||||
'amount' => get_post_meta( $coupon_id, 'coupon_amount', true ),
|
||||
'usage_count' => get_post_meta( $coupon_id, 'usage_count', true ),
|
||||
|
@ -180,7 +181,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
'usage_limit_per_user' => 'usage_limit_per_user',
|
||||
'limit_usage_to_x_items' => 'limit_usage_to_x_items',
|
||||
'usage_count' => 'usage_count',
|
||||
'expiry_date' => 'date_expires',
|
||||
'date_expires' => 'date_expires',
|
||||
'free_shipping' => 'free_shipping',
|
||||
'product_categories' => 'product_categories',
|
||||
'exclude_product_categories' => 'excluded_product_categories',
|
||||
|
@ -210,6 +211,10 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
|||
case 'email_restrictions' :
|
||||
$updated = update_post_meta( $coupon->get_id(), $meta_key, array_filter( array_map( 'sanitize_email', $value ) ) );
|
||||
break;
|
||||
case 'date_expires' :
|
||||
$updated = update_post_meta( $coupon->get_id(), $meta_key, ( $value ? $value->getTimestamp() : null ) );
|
||||
update_post_meta( $coupon->get_id(), 'expiry_date', ( $value ? $value->date( 'Y-m-d' ) : '' ) ); // Update the old meta key for backwards compatibility.
|
||||
break;
|
||||
default :
|
||||
$updated = update_post_meta( $coupon->get_id(), $meta_key, $value );
|
||||
break;
|
||||
|
|
|
@ -20,6 +20,11 @@ class WC_Customer_Download_Data_Store implements WC_Customer_Download_Data_Store
|
|||
public function create( &$download ) {
|
||||
global $wpdb;
|
||||
|
||||
// Always set a access granted date.
|
||||
if ( is_null( $download->get_access_granted( 'edit' ) ) ) {
|
||||
$download->set_access_granted( current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'download_id' => $download->get_download_id( 'edit' ),
|
||||
'product_id' => $download->get_product_id( 'edit' ),
|
||||
|
@ -28,9 +33,9 @@ class WC_Customer_Download_Data_Store implements WC_Customer_Download_Data_Store
|
|||
'order_id' => $download->get_order_id( 'edit' ),
|
||||
'order_key' => $download->get_order_key( 'edit' ),
|
||||
'downloads_remaining' => $download->get_downloads_remaining( 'edit' ),
|
||||
'access_granted' => date( 'Y-m-d', $download->get_access_granted( 'edit' ) ),
|
||||
'access_granted' => date( 'Y-m-d', $download->get_access_granted( 'edit' )->getTimestamp() ),
|
||||
'download_count' => $download->get_download_count( 'edit' ),
|
||||
'access_expires' => $download->get_access_expires( 'edit' ) ? date( 'Y-m-d', $download->get_access_expires( 'edit' ) ) : null,
|
||||
'access_expires' => ! is_null( $download->get_access_expires( 'edit' ) ) ? date( 'Y-m-d', $download->get_access_expires( 'edit' )->getTimestamp() ) : null,
|
||||
);
|
||||
|
||||
$format = array(
|
||||
|
@ -94,9 +99,9 @@ class WC_Customer_Download_Data_Store implements WC_Customer_Download_Data_Store
|
|||
'order_id' => $download->get_order_id( 'edit' ),
|
||||
'order_key' => $download->get_order_key( 'edit' ),
|
||||
'downloads_remaining' => $download->get_downloads_remaining( 'edit' ),
|
||||
'access_granted' => date( 'Y-m-d', $download->get_access_granted( 'edit' ) ),
|
||||
'access_granted' => date( 'Y-m-d', $download->get_access_granted( 'edit' )->getTimestamp() ),
|
||||
'download_count' => $download->get_download_count( 'edit' ),
|
||||
'access_expires' => $download->get_access_expires( 'edit' ) ? date( 'Y-m-d', $download->get_access_expires( 'edit' ) ) : null,
|
||||
'access_expires' => ! is_null( $download->get_access_expires( 'edit' ) ) ? date( 'Y-m-d', $download->get_access_expires( 'edit' )->getTimestamp() ) : null,
|
||||
);
|
||||
|
||||
$format = array(
|
||||
|
|
|
@ -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,
|
||||
) );
|
||||
|
@ -160,15 +170,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() : '' );
|
||||
|
||||
// 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' ) : '' );
|
||||
|
||||
} 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() : '' );
|
||||
|
||||
// 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' ) : '' );
|
||||
|
||||
} else {
|
||||
update_post_meta( $id, $meta_key, $value );
|
||||
}
|
||||
|
||||
$updated_props[] = $prop;
|
||||
}
|
||||
|
||||
|
@ -454,7 +483,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
|||
WHERE posts.post_type IN ('" . implode( "','", wc_get_order_types() ) . "')
|
||||
AND posts.post_status = 'wc-pending'
|
||||
AND posts.post_modified < %s
|
||||
", date( "Y-m-d H:i:s", absint( $date ) ) ) );
|
||||
", date( 'Y-m-d H:i:s', absint( $date ) ) ) );
|
||||
|
||||
return $unpaid_orders;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
*/
|
||||
public function create( &$product ) {
|
||||
if ( ! $product->get_date_created() ) {
|
||||
$product->set_date_created( current_time( 'timestamp' ) );
|
||||
$product->set_date_created( current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$id = wp_insert_post( apply_filters( 'woocommerce_new_product_data', array(
|
||||
|
@ -91,8 +91,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
'comment_status' => $product->get_reviews_allowed() ? 'open' : 'closed',
|
||||
'ping_status' => 'closed',
|
||||
'menu_order' => $product->get_menu_order(),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created() ),
|
||||
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $product->get_date_created() ) ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getTimestamp() ),
|
||||
) ), true );
|
||||
|
||||
if ( $id && ! is_wp_error( $id ) ) {
|
||||
|
@ -130,8 +130,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
$product->set_props( array(
|
||||
'name' => $post_object->post_title,
|
||||
'slug' => $post_object->post_name,
|
||||
'date_created' => $post_object->post_date,
|
||||
'date_modified' => $post_object->post_modified,
|
||||
'date_created' => strtotime( $post_object->post_date_gmt ),
|
||||
'date_modified' => strtotime( $post_object->post_modified_gmt ),
|
||||
'status' => $post_object->post_status,
|
||||
'description' => $post_object->post_content,
|
||||
'short_description' => $post_object->post_excerpt,
|
||||
|
@ -159,7 +159,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
// Only update the post when the post data changes.
|
||||
if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order', 'date_created', 'date_modified' ), array_keys( $changes ) ) ) {
|
||||
wp_update_post( array(
|
||||
'ID' => $product->get_id(),
|
||||
'ID' => $product->get_id(),
|
||||
'post_content' => $product->get_description( 'edit' ),
|
||||
'post_excerpt' => $product->get_short_description( 'edit' ),
|
||||
'post_title' => $product->get_name( 'edit' ),
|
||||
|
@ -167,10 +167,10 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
'comment_status' => $product->get_reviews_allowed( 'edit' ) ? 'open' : 'closed',
|
||||
'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish',
|
||||
'menu_order' => $product->get_menu_order( 'edit' ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' ) ),
|
||||
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' ) ) ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' ) ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? get_gmt_from_date( date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' ) ) ) : current_time( 'mysql', 1 ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getTimestamp() ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
|
||||
) );
|
||||
}
|
||||
|
||||
|
@ -451,6 +451,10 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
}
|
||||
$updated = true;
|
||||
break;
|
||||
case 'date_on_sale_from' :
|
||||
case 'date_on_sale_to' :
|
||||
$updated = update_post_meta( $product->get_id(), $meta_key, $value ? $value->getTimestamp() : '' );
|
||||
break;
|
||||
default :
|
||||
$updated = update_post_meta( $product->get_id(), $meta_key, $value );
|
||||
break;
|
||||
|
@ -811,7 +815,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
AND postmeta.meta_value > 0
|
||||
AND postmeta.meta_value < %s
|
||||
AND postmeta_2.meta_value != postmeta_3.meta_value
|
||||
", current_time( 'timestamp' ) ) );
|
||||
", current_time( 'timestamp', true ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -832,7 +836,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
AND postmeta.meta_value > 0
|
||||
AND postmeta.meta_value < %s
|
||||
AND postmeta_2.meta_value != postmeta_3.meta_value
|
||||
", current_time( 'timestamp' ) ) );
|
||||
", current_time( 'timestamp', true ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,13 +56,13 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
|||
}
|
||||
|
||||
$product->set_props( array(
|
||||
'name' => $post_object->post_title,
|
||||
'slug' => $post_object->post_name,
|
||||
'date_created' => $post_object->post_date,
|
||||
'date_modified' => $post_object->post_modified,
|
||||
'status' => $post_object->post_status,
|
||||
'menu_order' => $post_object->menu_order,
|
||||
'reviews_allowed' => 'open' === $post_object->comment_status,
|
||||
'name' => $post_object->post_title,
|
||||
'slug' => $post_object->post_name,
|
||||
'date_created' => strtotime( $post_object->post_date_gmt ),
|
||||
'date_modified' => strtotime( $post_object->post_modified_gmt ),
|
||||
'status' => $post_object->post_status,
|
||||
'menu_order' => $post_object->menu_order,
|
||||
'reviews_allowed' => 'open' === $post_object->comment_status,
|
||||
) );
|
||||
|
||||
$this->read_product_data( $product );
|
||||
|
@ -92,7 +92,9 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
|||
* @param WC_Product
|
||||
*/
|
||||
public function create( &$product ) {
|
||||
$product->set_date_created( current_time( 'timestamp' ) );
|
||||
if ( ! $product->get_date_created() ) {
|
||||
$product->set_date_created( current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$id = wp_insert_post( apply_filters( 'woocommerce_new_product_variation_data', array(
|
||||
'post_type' => 'product_variation',
|
||||
|
@ -104,8 +106,8 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
|||
'comment_status' => 'closed',
|
||||
'ping_status' => 'closed',
|
||||
'menu_order' => $product->get_menu_order(),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created() ),
|
||||
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $product->get_date_created() ) ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getTimestamp() ),
|
||||
) ), true );
|
||||
|
||||
if ( $id && ! is_wp_error( $id ) ) {
|
||||
|
@ -146,10 +148,10 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
|||
'comment_status' => 'closed',
|
||||
'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish',
|
||||
'menu_order' => $product->get_menu_order( 'edit' ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' ) ),
|
||||
'post_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' ) ) ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' ) ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? get_gmt_from_date( date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' ) ) ) : current_time( 'mysql', 1 ),
|
||||
'post_date' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => date( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getTimestamp() ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? date( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
|
||||
) );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -85,10 +85,10 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
|
|||
$value = $this->get_catalog_visibility();
|
||||
break;
|
||||
case 'sale_price_dates_from' :
|
||||
$value = $this->get_date_on_sale_from();
|
||||
return $this->get_date_on_sale_from() ? $this->get_date_on_sale_from()->getTimestamp() : '';
|
||||
break;
|
||||
case 'sale_price_dates_to' :
|
||||
$value = $this->get_date_on_sale_to();
|
||||
return $this->get_date_on_sale_to() ? $this->get_date_on_sale_to()->getTimestamp() : '';
|
||||
break;
|
||||
case 'post' :
|
||||
$value = get_post( $this->get_id() );
|
||||
|
|
|
@ -111,7 +111,7 @@ abstract class WC_Legacy_Coupon extends WC_Data {
|
|||
$value = $this->get_usage_count();
|
||||
break;
|
||||
case 'expiry_date' :
|
||||
$value = $this->get_date_expires();
|
||||
$value = ( $this->get_date_expires() ? $this->get_date_expires()->date( 'Y-m-d' ) : '' );
|
||||
break;
|
||||
case 'product_categories' :
|
||||
$value = $this->get_product_categories();
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -371,14 +371,14 @@ function wc_downloadable_file_permission( $download_id, $product, $order, $qty =
|
|||
$download->set_user_email( $order->get_billing_email() );
|
||||
$download->set_order_key( $order->get_order_key() );
|
||||
$download->set_downloads_remaining( 0 > $product->get_download_limit() ? '' : $product->get_download_limit() * $qty );
|
||||
$download->set_access_granted( current_time( 'timestamp' ) );
|
||||
$download->set_access_granted( current_time( 'timestamp', true ) );
|
||||
$download->set_download_count( 0 );
|
||||
|
||||
$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() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -563,7 +563,7 @@ add_action( 'update_user_meta', 'wc_meta_update_last_update_time', 10, 4 );
|
|||
* @param int $user_id The user to set a timestamp for.
|
||||
*/
|
||||
function wc_set_user_last_update_time( $user_id ) {
|
||||
update_user_meta( $user_id, 'last_update', time() );
|
||||
update_user_meta( $user_id, 'last_update', gmdate( 'U' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -51,18 +51,21 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
|||
'id' => $coupon_1->get_id(),
|
||||
'code' => 'dummycoupon-1',
|
||||
'amount' => '1.00',
|
||||
'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ),
|
||||
'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ),
|
||||
'discount_type' => 'fixed_cart',
|
||||
'description' => 'This is a dummy coupon',
|
||||
'date_expires' => '',
|
||||
'date_expires_gmt' => '',
|
||||
'usage_count' => 0,
|
||||
'individual_use' => false,
|
||||
'product_ids' => array(),
|
||||
'excluded_product_ids' => array(),
|
||||
'usage_limit' => '',
|
||||
'usage_limit_per_user' => '',
|
||||
'limit_usage_to_x_items' => 0,
|
||||
'limit_usage_to_x_items' => null,
|
||||
'free_shipping' => false,
|
||||
'product_categories' => array(),
|
||||
'excluded_product_categories' => array(),
|
||||
|
@ -113,18 +116,21 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
|||
'id' => $coupon->get_id(),
|
||||
'code' => 'dummycoupon-1',
|
||||
'amount' => '1.00',
|
||||
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt ),
|
||||
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ),
|
||||
'discount_type' => 'fixed_cart',
|
||||
'description' => 'This is a dummy coupon',
|
||||
'date_expires' => null,
|
||||
'date_expires_gmt' => null,
|
||||
'usage_count' => 0,
|
||||
'individual_use' => false,
|
||||
'product_ids' => array(),
|
||||
'excluded_product_ids' => array(),
|
||||
'usage_limit' => null,
|
||||
'usage_limit_per_user' => null,
|
||||
'limit_usage_to_x_items' => 0,
|
||||
'limit_usage_to_x_items' => null,
|
||||
'free_shipping' => false,
|
||||
'product_categories' => array(),
|
||||
'excluded_product_categories' => array(),
|
||||
|
@ -181,17 +187,20 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
|||
'code' => 'test',
|
||||
'amount' => '5.00',
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'discount_type' => 'fixed_product',
|
||||
'description' => 'Test',
|
||||
'date_expires' => null,
|
||||
'date_expires_gmt' => null,
|
||||
'usage_count' => 0,
|
||||
'individual_use' => false,
|
||||
'product_ids' => array(),
|
||||
'excluded_product_ids' => array(),
|
||||
'usage_limit' => 10,
|
||||
'usage_limit_per_user' => null,
|
||||
'limit_usage_to_x_items' => 0,
|
||||
'limit_usage_to_x_items' => null,
|
||||
'free_shipping' => false,
|
||||
'product_categories' => array(),
|
||||
'excluded_product_categories' => array(),
|
||||
|
@ -406,15 +415,18 @@ class WC_Tests_API_Coupons extends WC_REST_Unit_Test_Case {
|
|||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertEquals( 24, count( $properties ) );
|
||||
$this->assertEquals( 27, count( $properties ) );
|
||||
$this->assertArrayHasKey( 'id', $properties );
|
||||
$this->assertArrayHasKey( 'code', $properties );
|
||||
$this->assertArrayHasKey( 'date_created', $properties );
|
||||
$this->assertArrayHasKey( 'date_created_gmt', $properties );
|
||||
$this->assertArrayHasKey( 'date_modified', $properties );
|
||||
$this->assertArrayHasKey( 'date_modified_gmt', $properties );
|
||||
$this->assertArrayHasKey( 'description', $properties );
|
||||
$this->assertArrayHasKey( 'discount_type', $properties );
|
||||
$this->assertArrayHasKey( 'amount', $properties );
|
||||
$this->assertArrayHasKey( 'date_expires', $properties );
|
||||
$this->assertArrayHasKey( 'date_expires_gmt', $properties );
|
||||
$this->assertArrayHasKey( 'usage_count', $properties );
|
||||
$this->assertArrayHasKey( 'individual_use', $properties );
|
||||
$this->assertArrayHasKey( 'product_ids', $properties );
|
||||
|
|
|
@ -51,15 +51,17 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( 2, count( $customers ) );
|
||||
|
||||
$this->assertContains( array(
|
||||
'id' => $customer_1->get_id(),
|
||||
'date_created' => wc_rest_prepare_date_response( date( 'Y-m-d H:i:s', $customer_1->get_date_created() ) ),
|
||||
'date_modified' => wc_rest_prepare_date_response( date( 'Y-m-d H:i:s', $customer_1->get_date_modified() ) ),
|
||||
'email' => 'test@woo.local',
|
||||
'first_name' => 'Justin',
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => 'testcustomer',
|
||||
'billing' => array(
|
||||
'id' => $customer_1->get_id(),
|
||||
'date_created' => wc_rest_prepare_date_response( $customer_1->get_date_created(), false ),
|
||||
'date_created_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_created() ),
|
||||
'date_modified' => wc_rest_prepare_date_response( $customer_1->get_date_modified(), false ),
|
||||
'date_modified_gmt' => wc_rest_prepare_date_response( $customer_1->get_date_modified() ),
|
||||
'email' => 'test@woo.local',
|
||||
'first_name' => 'Justin',
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => 'testcustomer',
|
||||
'billing' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -72,7 +74,7 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'email' => '',
|
||||
'phone' => '',
|
||||
),
|
||||
'shipping' => array(
|
||||
'shipping' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -84,11 +86,11 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'country' => 'US',
|
||||
),
|
||||
'is_paying_customer' => false,
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $customer_1->get_avatar_url(),
|
||||
'meta_data' => array(),
|
||||
'_links' => array(
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $customer_1->get_avatar_url(),
|
||||
'meta_data' => array(),
|
||||
'_links' => array(
|
||||
'self' => array(
|
||||
array(
|
||||
'href' => rest_url( '/wc/v2/customers/' . $customer_1->get_id() . '' ),
|
||||
|
@ -134,15 +136,17 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertEquals( array(
|
||||
'id' => $data['id'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'email' => 'create_customer_test@woo.local',
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => 'create_customer_test',
|
||||
'billing' => array(
|
||||
'id' => $data['id'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'email' => 'create_customer_test@woo.local',
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => 'create_customer_test',
|
||||
'billing' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -155,7 +159,7 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'email' => '',
|
||||
'phone' => '',
|
||||
),
|
||||
'shipping' => array(
|
||||
'shipping' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -167,10 +171,10 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'country' => '',
|
||||
),
|
||||
'is_paying_customer' => false,
|
||||
'meta_data' => array(),
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $data['avatar_url'],
|
||||
'meta_data' => array(),
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $data['avatar_url'],
|
||||
), $data );
|
||||
|
||||
// Test extra data
|
||||
|
@ -195,15 +199,17 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertEquals( array(
|
||||
'id' => $data['id'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'email' => 'create_customer_test2@woo.local',
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'McTestFace',
|
||||
'role' => 'customer',
|
||||
'username' => 'create_customer_test2',
|
||||
'billing' => array(
|
||||
'id' => $data['id'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'email' => 'create_customer_test2@woo.local',
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'McTestFace',
|
||||
'role' => 'customer',
|
||||
'username' => 'create_customer_test2',
|
||||
'billing' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -216,7 +222,7 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'email' => '',
|
||||
'phone' => '',
|
||||
),
|
||||
'shipping' => array(
|
||||
'shipping' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -228,10 +234,10 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'country' => 'US',
|
||||
),
|
||||
'is_paying_customer' => false,
|
||||
'meta_data' => array(),
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $data['avatar_url'],
|
||||
'meta_data' => array(),
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $data['avatar_url'],
|
||||
), $data );
|
||||
|
||||
// Test without required field
|
||||
|
@ -276,12 +282,14 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( array(
|
||||
'id' => $data['id'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'email' => 'get_customer_test@woo.local',
|
||||
'first_name' => 'Justin',
|
||||
'billing' => array(
|
||||
'id' => $data['id'],
|
||||
'date_created' => $data['date_created'],
|
||||
'date_created_gmt' => $data['date_created_gmt'],
|
||||
'date_modified' => $data['date_modified'],
|
||||
'date_modified_gmt' => $data['date_modified_gmt'],
|
||||
'email' => 'get_customer_test@woo.local',
|
||||
'first_name' => 'Justin',
|
||||
'billing' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -294,7 +302,7 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'email' => '',
|
||||
'phone' => '',
|
||||
),
|
||||
'shipping' => array(
|
||||
'shipping' => array(
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'company' => '',
|
||||
|
@ -306,13 +314,13 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
'country' => 'US',
|
||||
),
|
||||
'is_paying_customer' => false,
|
||||
'meta_data' => array(),
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => 'get_customer_test',
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $data['avatar_url'],
|
||||
'meta_data' => array(),
|
||||
'last_name' => '',
|
||||
'role' => 'customer',
|
||||
'username' => 'get_customer_test',
|
||||
'orders_count' => 0,
|
||||
'total_spent' => '0.00',
|
||||
'avatar_url' => $data['avatar_url'],
|
||||
), $data );
|
||||
}
|
||||
|
||||
|
@ -491,10 +499,12 @@ class Customers extends WC_REST_Unit_Test_Case {
|
|||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertEquals( 16, count( $properties ) );
|
||||
$this->assertEquals( 18, count( $properties ) );
|
||||
$this->assertArrayHasKey( 'id', $properties );
|
||||
$this->assertArrayHasKey( 'date_created', $properties );
|
||||
$this->assertArrayHasKey( 'date_created_gmt', $properties );
|
||||
$this->assertArrayHasKey( 'date_modified', $properties );
|
||||
$this->assertArrayHasKey( 'date_modified_gmt', $properties );
|
||||
$this->assertArrayHasKey( 'email', $properties );
|
||||
$this->assertArrayHasKey( 'first_name', $properties );
|
||||
$this->assertArrayHasKey( 'last_name', $properties );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ class Product_Variations_API extends WC_REST_Unit_Test_Case {
|
|||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertEquals( 35, count( $properties ) );
|
||||
$this->assertEquals( 37, count( $properties ) );
|
||||
$this->assertArrayHasKey( 'id', $properties );
|
||||
$this->assertArrayHasKey( 'date_created', $properties );
|
||||
$this->assertArrayHasKey( 'date_modified', $properties );
|
||||
|
|
|
@ -477,7 +477,7 @@ class Products_API extends WC_REST_Unit_Test_Case {
|
|||
$response = $this->server->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertEquals( 62, count( $properties ) );
|
||||
$this->assertEquals( 66, count( $properties ) );
|
||||
$product->delete( true );
|
||||
}
|
||||
|
||||
|
|
|
@ -249,4 +249,26 @@ class WC_Tests_Coupon extends WC_Unit_Test_Case {
|
|||
// Delete product
|
||||
WC_Helper_Product::delete_product( $product->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test date setters/getters.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function test_dates() {
|
||||
$valid_coupon = WC_Helper_Coupon::create_coupon();
|
||||
$valid_coupon->set_date_expires( time() + 1000 );
|
||||
$valid_coupon->set_date_created( time() );
|
||||
$valid_coupon->set_date_modified( time() );
|
||||
|
||||
$expired_coupon = WC_Helper_Coupon::create_coupon();
|
||||
$expired_coupon->set_date_expires( time() - 10 );
|
||||
$expired_coupon->set_date_created( time() - 20 );
|
||||
$expired_coupon->set_date_modified( time() - 20 );
|
||||
|
||||
$this->assertInstanceOf( 'WC_DateTime', $valid_coupon->get_date_created() );
|
||||
$this->assertTrue( $valid_coupon->is_valid() );
|
||||
$this->assertFalse( $expired_coupon->is_valid() );
|
||||
$this->assertEquals( $expired_coupon->get_error_message(), $expired_coupon->get_coupon_error( WC_Coupon::E_WC_COUPON_EXPIRED ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,6 +99,22 @@ class WC_Tests_Coupon_Data_Store extends WC_Unit_Test_Case {
|
|||
$this->assertNotEquals( 0, $new_coupon_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test coupon date saving/loading.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
function test_coupon_date_saving() {
|
||||
$expiry_date = time() - 10;
|
||||
|
||||
$coupon = WC_Helper_Coupon::create_coupon( 'coupon-' . time());
|
||||
$coupon->set_date_expires( $expiry_date );
|
||||
$coupon->save();
|
||||
|
||||
$coupon_read = new WC_Coupon( $coupon->get_id() );
|
||||
|
||||
$this->assertEquals( date( 'Y-m-d', $expiry_date ), date( 'Y-m-d', $coupon_read->get_date_expires()->getTimestamp() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test coupon increase, decrease, user usage count methods.
|
||||
* @since 2.7.0
|
||||
|
|
|
@ -163,7 +163,6 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case {
|
|||
'description' => 'hello world',
|
||||
'discount_type' => 'percent',
|
||||
'amount' => 10.50,
|
||||
'date_expires' => time(),
|
||||
'usage_count' => 5,
|
||||
'individual_use' => true,
|
||||
'product_ids' => array( 5, 10 ),
|
||||
|
|
|
@ -291,6 +291,112 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 'val1', $object->get_meta( 'test_field_2' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected method set_date_prop by testing a order date setter.
|
||||
*/
|
||||
function test_set_date_prop_gmt_offset() {
|
||||
$object = new WC_Order();
|
||||
|
||||
// Change timezone in WP.
|
||||
update_option( 'gmt_offset', -4 );
|
||||
|
||||
// Set date to a UTC timestamp and expect a valid UTC timestamp back.
|
||||
$object->set_date_created( 1488979186 );
|
||||
$this->assertEquals( 1488979186, $object->get_date_created()->getTimestamp() );
|
||||
|
||||
// Set date to a string without timezone info. This will be assumed in local timezone and thus should match the offset timestamp.
|
||||
$object->set_date_created( '2017-01-02' );
|
||||
$this->assertEquals( 1483315200 - $object->get_date_created()->getOffset(), $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getOffsetTimestamp() );
|
||||
$this->assertEquals( '2017-01-02 00:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// Date time with no timezone.
|
||||
$object->set_date_created( '2017-01-02T00:00' );
|
||||
$this->assertEquals( 1483315200 - $object->get_date_created()->getOffset(), $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getOffsetTimestamp() );
|
||||
$this->assertEquals( '2017-01-02 00:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// ISO 8601 date time with offset.
|
||||
$object->set_date_created( '2017-01-01T20:00:00-04:00' );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( '2017-01-01 20:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// ISO 8601 date time different offset to site timezone.
|
||||
$object->set_date_created( '2017-01-01T16:00:00-08:00' );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( '2017-01-01 20:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// ISO 8601 date time in UTC.
|
||||
$object->set_date_created( '2017-01-02T00:00:00+00:00' );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( '2017-01-01 20:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// Restore default.
|
||||
update_option( 'gmt_offset', 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected method set_date_prop by testing a order date setter.
|
||||
*/
|
||||
function test_set_date_prop_timezone_string() {
|
||||
$object = new WC_Order();
|
||||
|
||||
// Repeat tests with timezone_string. America/New_York is -5 in the winter and -4 in summer.
|
||||
update_option( 'timezone_string', 'America/New_York' );
|
||||
|
||||
// Set date to a UTC timestamp and expect a valid UTC timestamp back.
|
||||
$object->set_date_created( 1488979186 );
|
||||
$this->assertEquals( 1488979186, $object->get_date_created()->getTimestamp() );
|
||||
|
||||
// Set date to a string without timezone info. This will be assumed in local timezone and thus should match the offset timestamp.
|
||||
$object->set_date_created( '2017-01-02' );
|
||||
$this->assertEquals( 1483315200 - $object->get_date_created()->getOffset(), $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getOffsetTimestamp() );
|
||||
$this->assertEquals( '2017-01-02 00:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// Date time with no timezone.
|
||||
$object->set_date_created( '2017-01-02T00:00' );
|
||||
$this->assertEquals( 1483315200 - $object->get_date_created()->getOffset(), $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getOffsetTimestamp() );
|
||||
$this->assertEquals( '2017-01-02 00:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// ISO 8601 date time with offset.
|
||||
$object->set_date_created( '2017-01-01T19:00:00-05:00' );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( '2017-01-01 19:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// ISO 8601 date time different offset to site timezone.
|
||||
$object->set_date_created( '2017-01-01T16:00:00-08:00' );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( '2017-01-01 19:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// ISO 8601 date time in UTC.
|
||||
$object->set_date_created( '2017-01-02T00:00:00+00:00' );
|
||||
$this->assertEquals( 1483315200, $object->get_date_created()->getTimestamp() );
|
||||
$this->assertEquals( '2017-01-01 19:00:00', $object->get_date_created()->date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
// Restore default.
|
||||
update_option( 'timezone_string', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected method set_date_prop by testing a order date setter.
|
||||
*/
|
||||
function test_set_date_prop_server_timezone() {
|
||||
// Repeat all tests with different server timezone.
|
||||
date_default_timezone_set( 'Pacific/Fiji' );
|
||||
$this->test_set_date_prop_gmt_offset();
|
||||
$this->test_set_date_prop_timezone_string();
|
||||
|
||||
// Repeat all tests with different server timezone.
|
||||
date_default_timezone_set( 'Pacific/Tahiti' );
|
||||
$this->test_set_date_prop_gmt_offset();
|
||||
$this->test_set_date_prop_timezone_string();
|
||||
|
||||
// Restore to UTC.
|
||||
date_default_timezone_set( 'UTC' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test applying changes
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( $username, $customer->get_username() );
|
||||
$this->assertNotEquals( 0, $customer->get_id() );
|
||||
$this->assertEquals( strtotime( $wp_user->user_registered ), $customer->get_date_created() );
|
||||
$this->assertEquals( strtotime( $wp_user->user_registered ), $customer->get_date_created()->getOffsetTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,7 +178,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
|||
*/
|
||||
public function test_customer_setters_and_getters() {
|
||||
$time = time();
|
||||
$standard_getters_and_setters = array(
|
||||
$setters = array(
|
||||
'username' => 'test',
|
||||
'email' => 'test@woo.local',
|
||||
'first_name' => 'Bob',
|
||||
|
@ -205,10 +205,22 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
|||
);
|
||||
|
||||
$customer = new WC_Customer;
|
||||
foreach ( $standard_getters_and_setters as $function => $value ) {
|
||||
$customer->{"set_{$function}"}( $value );
|
||||
$this->assertEquals( $value, $customer->{"get_{$function}"}(), $function );
|
||||
|
||||
foreach ( $setters as $method => $value ) {
|
||||
$customer->{"set_{$method}"}( $value );
|
||||
}
|
||||
|
||||
$getters = array();
|
||||
|
||||
foreach ( $setters as $method => $value ) {
|
||||
$getters[ $method ] = $customer->{"get_{$method}"}();
|
||||
}
|
||||
|
||||
// Get timestamps from date_created and date_modified.
|
||||
$getters['date_created'] = $getters['date_created']->getOffsetTimestamp();
|
||||
$getters['date_modified'] = $getters['date_modified']->getOffsetTimestamp();
|
||||
|
||||
$this->assertEquals( $setters, $getters );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,7 +286,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
|||
$customer = WC_Helper_Customer::create_customer();
|
||||
$customer_id = $customer->get_id();
|
||||
$user = new WP_User( $customer_id );
|
||||
$this->assertEquals( strtotime( $user->data->user_registered ), $customer->get_date_created() );
|
||||
$this->assertEquals( strtotime( $user->data->user_registered ), $customer->get_date_created()->getOffsetTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,11 +298,11 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
|
|||
$customer_id = $customer->get_id();
|
||||
$last = get_user_meta( $customer_id, 'last_update', true );
|
||||
sleep( 1 );
|
||||
$this->assertEquals( $last, $customer->get_date_modified() );
|
||||
$this->assertEquals( $last, $customer->get_date_modified()->getOffsetTimestamp() );
|
||||
$customer->set_billing_address( '1234 Some St.' );
|
||||
$customer->save();
|
||||
$update = get_user_meta( $customer_id, 'last_update', true );
|
||||
$this->assertEquals( $update, $customer->get_date_modified() );
|
||||
$this->assertEquals( $update, $customer->get_date_modified()->getOffsetTimestamp() );
|
||||
$this->assertNotEquals( $update, $last );
|
||||
}
|
||||
|
||||
|
|
|
@ -97,10 +97,10 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
|
|||
function test_get_date_created() {
|
||||
$object = new WC_Order();
|
||||
$object->set_date_created( '2016-12-12' );
|
||||
$this->assertEquals( '1481500800', $object->get_date_created() );
|
||||
$this->assertEquals( '1481500800', $object->get_date_created()->getOffsetTimestamp() );
|
||||
|
||||
$object->set_date_created( '1481500800' );
|
||||
$this->assertEquals( 1481500800, $object->get_date_created() );
|
||||
$this->assertEquals( 1481500800, $object->get_date_created()->getTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,10 +109,10 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
|
|||
function test_get_date_modified() {
|
||||
$object = new WC_Order();
|
||||
$object->set_date_modified( '2016-12-12' );
|
||||
$this->assertEquals( '1481500800', $object->get_date_modified() );
|
||||
$this->assertEquals( '1481500800', $object->get_date_modified()->getOffsetTimestamp() );
|
||||
|
||||
$object->set_date_modified( '1481500800' );
|
||||
$this->assertEquals( 1481500800, $object->get_date_modified() );
|
||||
$this->assertEquals( 1481500800, $object->get_date_modified()->getTimestamp() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1060,10 +1060,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() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1073,10 +1073,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() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,8 +34,6 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
'sku' => 'TEST SKU',
|
||||
'regular_price' => 15.00,
|
||||
'sale_price' => 10.00,
|
||||
'date_on_sale_from' => '1475798400',
|
||||
'date_on_sale_to' => '1477267200',
|
||||
'total_sales' => 20,
|
||||
'tax_status' => 'none',
|
||||
'tax_class' => '',
|
||||
|
@ -64,11 +62,15 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
$product->{"set_{$function}"}( $value );
|
||||
}
|
||||
$product->set_date_on_sale_from( '1475798400' );
|
||||
$product->set_date_on_sale_to( '1477267200' );
|
||||
$product->save();
|
||||
$product = new WC_Product_Simple( $product->get_id() );
|
||||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
|
||||
}
|
||||
$this->assertEquals( $product->get_date_on_sale_from()->getTimestamp(), 1475798400 );
|
||||
$this->assertEquals( $product->get_date_on_sale_to()->getTimestamp(), 1477267200 );
|
||||
|
||||
$image_url = media_sideload_image( "https://cldup.com/Dr1Bczxq4q.png", $product->get_id(), '', 'src' );
|
||||
$image_id = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) );
|
||||
|
|
|
@ -296,6 +296,7 @@ final class WooCommerce {
|
|||
* Core classes.
|
||||
*/
|
||||
include_once( WC_ABSPATH . 'includes/wc-core-functions.php' );
|
||||
include_once( WC_ABSPATH . 'includes/class-wc-datetime.php' );
|
||||
include_once( WC_ABSPATH . 'includes/class-wc-post-types.php' ); // Registers post types
|
||||
include_once( WC_ABSPATH . 'includes/class-wc-install.php' );
|
||||
include_once( WC_ABSPATH . 'includes/class-wc-geolocation.php' );
|
||||
|
|
Loading…
Reference in New Issue