FUpdate how save download dates

This commit is contained in:
Claudio Sanches 2017-03-13 20:54:33 -03:00
parent aaeab5b81e
commit c4134586cd
3 changed files with 11 additions and 6 deletions

View File

@ -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 );
}
}

View File

@ -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(

View File

@ -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();