commit
29dee59fde
|
@ -259,19 +259,31 @@ function woocommerce_order_downloads_save( $post_id, $post ) {
|
|||
$customer_user = (int) get_post_meta($post->ID, '_customer_user', true);
|
||||
|
||||
for ($i=0; $i<sizeof($download_ids); $i++) :
|
||||
|
||||
$wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions", array(
|
||||
|
||||
$data = array(
|
||||
'user_id' => $customer_user,
|
||||
'user_email' => $customer_email,
|
||||
'downloads_remaining' => $downloads_remaining[$i],
|
||||
'access_expires' => ($access_expires[$i]) ? date('Y-m-d', strtotime($access_expires[$i])) : ''
|
||||
), array(
|
||||
);
|
||||
|
||||
$format = array( '%d', '%s', '%s');
|
||||
|
||||
$expiry = array_key_exists($i, $access_expires) ? date('Y-m-d', strtotime($access_expires[$i])) : null;
|
||||
|
||||
if ( ! is_null($expiry)) {
|
||||
$data['access_expires'] = $expiry;
|
||||
$format[] = '%s';
|
||||
}
|
||||
|
||||
$wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions",
|
||||
$data,
|
||||
array(
|
||||
'order_id' => $post_id,
|
||||
'product_id' => $download_ids[$i]
|
||||
), array( '%d', '%s', '%s', '%s' ), array( '%d', '%d' ) );
|
||||
), $format, array( '%d', '%d' ) );
|
||||
|
||||
endfor;
|
||||
|
||||
endif;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -548,41 +548,54 @@ function woocommerce_grant_access_to_download() {
|
|||
$limit = trim(get_post_meta($product_id, '_download_limit', true));
|
||||
$expiry = trim(get_post_meta($product_id, '_download_expiry', true));
|
||||
|
||||
$limit = (empty($limit)) ? '' : (int) $limit;
|
||||
$expiry = (empty($expiry)) ? '' : (int) $expiry;
|
||||
$limit = (empty($limit)) ? '' : (int) $limit;
|
||||
|
||||
// Default value is NULL in the table schema
|
||||
$expiry = (empty($expiry)) ? null : (int) $expiry;
|
||||
|
||||
if ($expiry) $expiry = date("Y-m-d", strtotime('NOW + ' . $expiry . ' DAY'));
|
||||
|
||||
$wpdb->hide_errors();
|
||||
|
||||
$success = $wpdb->insert( $wpdb->prefix . 'woocommerce_downloadable_product_permissions', array(
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $order->user_id,
|
||||
'user_email' => $user_email,
|
||||
'order_id' => $order->id,
|
||||
'order_key' => $order->order_key,
|
||||
'downloads_remaining' => $limit,
|
||||
'access_granted' => current_time('mysql'),
|
||||
'access_expires' => $expiry,
|
||||
'download_count' => 0
|
||||
), array(
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%d'
|
||||
) );
|
||||
|
||||
$data = array(
|
||||
'product_id' => $product_id,
|
||||
'user_id' => $order->user_id,
|
||||
'user_email' => $user_email,
|
||||
'order_id' => $order->id,
|
||||
'order_key' => $order->order_key,
|
||||
'downloads_remaining' => $limit,
|
||||
'access_granted' => current_time('mysql'),
|
||||
'download_count' => 0
|
||||
);
|
||||
|
||||
$format = array(
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%d'
|
||||
);
|
||||
|
||||
if ( ! is_null($expiry)) {
|
||||
$data['access_expires'] = $expiry;
|
||||
$format[] = '%s';
|
||||
}
|
||||
|
||||
// Downloadable product - give access to the customer
|
||||
$success = $wpdb->insert( $wpdb->prefix . 'woocommerce_downloadable_product_permissions',
|
||||
$data,
|
||||
$format
|
||||
);
|
||||
|
||||
if ($success) {
|
||||
echo json_encode(array(
|
||||
'success' => 1,
|
||||
'download_id' => $product_id,
|
||||
'title' => get_the_title($product_id),
|
||||
'expires' => $expiry,
|
||||
'expires' => is_null($expiry) ? '' : $expiry,
|
||||
'remaining' => $limit
|
||||
));
|
||||
}
|
||||
|
|
|
@ -591,23 +591,25 @@ function woocommerce_downloadable_product_permissions( $order_id ) {
|
|||
$limit = trim(get_post_meta($download_id, '_download_limit', true));
|
||||
$expiry = trim(get_post_meta($download_id, '_download_expiry', true));
|
||||
|
||||
$limit = (empty($limit)) ? '' : (int) $limit;
|
||||
$expiry = (empty($expiry)) ? '' : (int) $expiry;
|
||||
$limit = (empty($limit)) ? '' : (int) $limit;
|
||||
|
||||
// Default value is NULL in the table schema
|
||||
$expiry = (empty($expiry)) ? null : (int) $expiry;
|
||||
|
||||
if ($expiry) $expiry = date("Y-m-d", strtotime('NOW + ' . $expiry . ' DAY'));
|
||||
|
||||
// Downloadable product - give access to the customer
|
||||
$wpdb->insert( $wpdb->prefix . 'woocommerce_downloadable_product_permissions', array(
|
||||
'product_id' => $download_id,
|
||||
|
||||
$data = array(
|
||||
'product_id' => $download_id,
|
||||
'user_id' => $order->user_id,
|
||||
'user_email' => $user_email,
|
||||
'order_id' => $order->id,
|
||||
'order_key' => $order->order_key,
|
||||
'downloads_remaining' => $limit,
|
||||
'access_granted' => current_time('mysql'),
|
||||
'access_expires' => $expiry,
|
||||
'download_count' => 0
|
||||
), array(
|
||||
);
|
||||
|
||||
$format = array(
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
|
@ -615,9 +617,19 @@ function woocommerce_downloadable_product_permissions( $order_id ) {
|
|||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s',
|
||||
'%d'
|
||||
) );
|
||||
);
|
||||
|
||||
if ( ! is_null($expiry)) {
|
||||
$data['access_expires'] = $expiry;
|
||||
$format[] = '%s';
|
||||
}
|
||||
|
||||
// Downloadable product - give access to the customer
|
||||
$wpdb->insert( $wpdb->prefix . 'woocommerce_downloadable_product_permissions',
|
||||
$data,
|
||||
$format
|
||||
);
|
||||
|
||||
endif;
|
||||
|
||||
|
@ -914,4 +926,4 @@ function woocommerce_let_to_num( $size ) {
|
|||
$ret *= 1024;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue