Merge pull request #4386 from justinstern/master

Downloadable File Fixes/Tweaks
This commit is contained in:
Mike Jolley 2013-12-23 05:20:36 -08:00
commit 17f79f651d
2 changed files with 10 additions and 8 deletions

View File

@ -285,11 +285,11 @@ class WC_Product {
} }
// Filter URL // Filter URL
$downloadable_files[ $key ]['file'] = apply_filters( 'woocommerce_file_download_path', $downloadable_files[ $key ]['file'], $this->id, $key ); $downloadable_files[ $key ]['file'] = apply_filters( 'woocommerce_file_download_path', $downloadable_files[ $key ]['file'], $this, $key );
} }
} }
return apply_filters( 'woocommerce_product_files', $downloadable_files, $this->id ); return apply_filters( 'woocommerce_product_files', $downloadable_files, $this );
} }
/** /**
@ -308,7 +308,7 @@ class WC_Product {
} }
// allow overriding based on the particular file being requested // allow overriding based on the particular file being requested
return apply_filters( 'woocommerce_product_file', $file, $this->id, $download_id ); return apply_filters( 'woocommerce_product_file', $file, $this, $download_id );
} }
/** /**
@ -327,7 +327,7 @@ class WC_Product {
} }
// allow overriding based on the particular file being requested // allow overriding based on the particular file being requested
return apply_filters( 'woocommerce_product_file_download_path', $file_path, $this->id, $download_id ); return apply_filters( 'woocommerce_product_file_download_path', $file_path, $this, $download_id );
} }
/** /**

View File

@ -94,8 +94,9 @@ function wc_downloadable_file_permission( $download_id, $product_id, $order ) {
return $result ? $wpdb->insert_id : false; 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_completed', 'wc_downloadable_product_permissions');
add_action('woocommerce_order_status_processing', 'wc_downloadable_product_permissions');
/** /**
@ -116,13 +117,14 @@ function wc_downloadable_product_permissions( $order_id ) {
$_product = $order->get_product_from_item( $item ); $_product = $order->get_product_from_item( $item );
if ( $_product && $_product->exists() && $_product->is_downloadable() ) { if ( $_product && $_product->exists() && $_product->is_downloadable() ) {
$downloads = get_post_meta( $_product->id, '_downloadable_files' ) ; $downloads = $_product->get_files();
foreach ( $downloads[0] as $download_id => $download ) foreach ( array_keys( $downloads ) as $download_id ) {
wc_downloadable_file_permission( $download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order ); wc_downloadable_file_permission( $download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order );
} }
} }
} }
}
update_post_meta( $order_id, '_download_permissions_granted', 1 ); update_post_meta( $order_id, '_download_permissions_granted', 1 );