Stop doing new queries only to get coupons gmt dates

This commit is contained in:
Claudio Sanches 2016-11-18 16:36:02 -02:00
parent 3074bd180f
commit 073c924b98
3 changed files with 9 additions and 14 deletions

View File

@ -108,15 +108,12 @@ class WC_API_Coupons extends WC_API_Resource {
}
$coupon = new WC_Coupon( $code );
$coupon_post = get_post( $coupon->get_id() );
$coupon_data = array(
'id' => $coupon->get_id(),
'code' => $coupon->get_code(),
'type' => $coupon->get_discount_type(),
'created_at' => $this->server->format_datetime( $coupon_post->post_date_gmt ),
'updated_at' => $this->server->format_datetime( $coupon_post->post_modified_gmt ),
'created_at' => $this->server->format_datetime( $coupon->get_date_created(), false, true ),
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified(), false, true ),
'amount' => wc_format_decimal( $coupon->get_amount(), 2 ),
'individual_use' => $coupon->get_individual_use(),
'product_ids' => array_map( 'absint', (array) $coupon->get_product_ids() ),
@ -125,7 +122,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() ),
'expiry_date' => $this->server->format_datetime( $coupon->get_date_expires(), false, true ),
'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() ),

View File

@ -118,14 +118,13 @@ class WC_API_Coupons extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_coupon_id', __( 'Invalid coupon ID', 'woocommerce' ), 404 );
}
$coupon = new WC_Coupon( $code );
$coupon_post = get_post( $coupon->get_id() );
$coupon = new WC_Coupon( $code );
$coupon_data = array(
'id' => $coupon->get_id(),
'code' => $coupon->get_code(),
'type' => $coupon->get_discount_type(),
'created_at' => $this->server->format_datetime( $coupon_post->post_date_gmt ),
'updated_at' => $this->server->format_datetime( $coupon_post->post_modified_gmt ),
'created_at' => $this->server->format_datetime( $coupon->get_date_created(), false, true ),
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified(), false, true ),
'amount' => wc_format_decimal( $coupon->get_amount(), 2 ),
'individual_use' => $coupon->get_individual_use(),
'product_ids' => array_map( 'absint', (array) $coupon->get_product_ids() ),

View File

@ -118,14 +118,13 @@ class WC_API_Coupons extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_coupon_id', __( 'Invalid coupon ID', 'woocommerce' ), 404 );
}
$coupon = new WC_Coupon( $code );
$coupon_post = get_post( $coupon->get_id() );
$coupon = new WC_Coupon( $code );
$coupon_data = array(
'id' => $coupon->get_id(),
'code' => $coupon->get_code(),
'type' => $coupon->get_discount_type(),
'created_at' => $this->server->format_datetime( $coupon_post->post_date_gmt ),
'updated_at' => $this->server->format_datetime( $coupon_post->post_modified_gmt ),
'created_at' => $this->server->format_datetime( $coupon->get_date_created(), false, true ),
'updated_at' => $this->server->format_datetime( $coupon->get_date_modified(), false, true ),
'amount' => wc_format_decimal( $coupon->get_amount(), 2 ),
'individual_use' => $coupon->get_individual_use(),
'product_ids' => array_map( 'absint', (array) $coupon->get_product_ids() ),