diff --git a/includes/class-wc-download-handler.php b/includes/class-wc-download-handler.php index 7e34decb39b..feb7be9953e 100644 --- a/includes/class-wc-download-handler.php +++ b/includes/class-wc-download-handler.php @@ -109,7 +109,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 ); } } diff --git a/includes/data-stores/class-wc-customer-download-data-store.php b/includes/data-stores/class-wc-customer-download-data-store.php index 4c5ff2e1e30..2cab1a40bcc 100644 --- a/includes/data-stores/class-wc-customer-download-data-store.php +++ b/includes/data-stores/class-wc-customer-download-data-store.php @@ -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( diff --git a/includes/wc-order-functions.php b/includes/wc-order-functions.php index 08f7e1920f2..ba738a70711 100644 --- a/includes/wc-order-functions.php +++ b/includes/wc-order-functions.php @@ -371,7 +371,7 @@ 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();