Prevent PHP Error in Customers API Endpoint (#37860)

Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
This commit is contained in:
Tyler Paulson 2023-04-21 02:14:24 -04:00 committed by GitHub
parent 8b8cc93f85
commit c19a42398b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Prevents error in Customers API endpoint when date_created value is missing

View File

@ -55,7 +55,7 @@ class WC_REST_Customers_V2_Controller extends WC_REST_Customers_V1_Controller {
// Format date values.
foreach ( $format_date as $key ) {
// Date created is stored UTC, date modified is stored WP local time.
$datetime = 'date_created' === $key ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $data[ $key ]->getTimestamp() ) ) : $data[ $key ];
$datetime = 'date_created' === $key && is_subclass_of( $data[ $key ], 'DateTime' ) ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $data[ $key ]->getTimestamp() ) ) : $data[ $key ];
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
}