Add product download access grant/revoke hooks.

This commit is contained in:
Illimar Tambek 2013-09-10 14:26:31 +03:00
parent c501b1b59a
commit f138007f1a
2 changed files with 30 additions and 23 deletions

View File

@ -55,8 +55,8 @@ function woocommerce_downloadable_file_permission( $download_id, $product_id, $o
if ( $expiry )
$expiry = date_i18n( "Y-m-d", strtotime( 'NOW + ' . $expiry . ' DAY' ) );
$data = array(
'download_id' => $download_id,
$data = apply_filters( 'woocommerce_downloadable_file_permission_data', array(
'download_id' => $download_id,
'product_id' => $product_id,
'user_id' => absint( $order->user_id ),
'user_email' => $user_email,
@ -65,10 +65,10 @@ function woocommerce_downloadable_file_permission( $download_id, $product_id, $o
'downloads_remaining' => $limit,
'access_granted' => current_time( 'mysql' ),
'download_count' => 0
);
));
$format = array(
'%s',
$format = apply_filters( 'woocommerce_downloadable_file_permission_format', array(
'%s',
'%s',
'%s',
'%s',
@ -77,23 +77,25 @@ function woocommerce_downloadable_file_permission( $download_id, $product_id, $o
'%s',
'%s',
'%d'
);
));
if ( ! is_null( $expiry ) ) {
$data['access_expires'] = $expiry;
$format[] = '%s';
}
if ( ! is_null( $expiry ) ) {
$data['access_expires'] = $expiry;
$format[] = '%s';
}
// Downloadable product - give access to the customer
$result = $wpdb->insert( $wpdb->prefix . 'woocommerce_downloadable_product_permissions',
apply_filters( 'woocommerce_downloadable_file_permission_data', $data ),
apply_filters( 'woocommerce_downloadable_file_permission_format', $format )
);
$data,
$format )
);
return $result ? $wpdb->insert_id : false;
do_action( 'woocommerce_grant_product_download_access', $data );
return $result ? $wpdb->insert_id : false;
}
add_action('woocommerce_order_status_completed', 'woocommerce_downloadable_product_permissions');
add_action( 'woocommerce_order_status_processing', 'woocommerce_downloadable_product_permissions' );
add_action('woocommerce_order_status_processing', 'woocommerce_downloadable_product_permissions');
/**
@ -133,6 +135,9 @@ function woocommerce_downloadable_product_permissions( $order_id ) {
endforeach;
update_post_meta( $order_id, __( 'Download Permissions Granted', 'woocommerce' ), 1);
do_action( 'woocommerce_grant_product_download_permissions', $order_id );
}
/**
@ -311,14 +316,14 @@ add_action( 'woocommerce_cancel_unpaid_orders', 'woocommerce_cancel_unpaid_order
function woocommerce_processing_order_count() {
if ( false === ( $order_count = get_transient( 'woocommerce_processing_order_count' ) ) ) {
$order_statuses = get_terms( 'shop_order_status' );
$order_count = false;
foreach ( $order_statuses as $status ) {
if( $status->slug === 'processing' ) {
$order_count += $status->count;
break;
}
}
$order_count = apply_filters( 'woocommerce_admin_menu_count', intval( $order_count ) );
$order_count = false;
foreach ( $order_statuses as $status ) {
if( $status->slug === 'processing' ) {
$order_count += $status->count;
break;
}
}
$order_count = apply_filters( 'woocommerce_admin_menu_count', intval( $order_count ) );
set_transient( 'woocommerce_processing_order_count', $order_count );
}

View File

@ -778,6 +778,8 @@ function woocommerce_revoke_access_to_download() {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %d;", $order_id, $product_id, $download_id ) );
do_action( 'woocommerce_ajax_revoke_access_to_product_download', $download_id, $product_id, $order_id );
die();
}