Merge pull request #23188 from LuigiPulcini/master

Add $item to wc_downloadable_file_permission
This commit is contained in:
Claudio Sanches 2021-03-25 12:19:08 -03:00 committed by GitHub
commit 50e036f934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -795,10 +795,14 @@ class WC_AJAX {
$loop = intval( $_POST['loop'] );
$file_counter = 0;
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
$files = $product->get_downloads();
foreach ( $items as $item ) {
$product = $item->get_product();
if ( ! in_array( $product->get_id(), $product_ids, true ) ) {
continue;
}
$files = $product->get_downloads();
if ( ! $order->get_billing_email() ) {
wp_die();
@ -806,7 +810,7 @@ class WC_AJAX {
if ( ! empty( $files ) ) {
foreach ( $files as $download_id => $file ) {
$inserted_id = wc_downloadable_file_permission( $download_id, $product_id, $order );
$inserted_id = wc_downloadable_file_permission( $download_id, $product_id, $order, $item->get_quantity(), $item );
if ( $inserted_id ) {
$download = new WC_Customer_Download( $inserted_id );
$loop ++;

View File

@ -366,9 +366,10 @@ function wc_orders_count( $status ) {
* @param int|WC_Product $product Product instance or ID.
* @param WC_Order $order Order data.
* @param int $qty Quantity purchased.
* @param WC_Order_Item $item Item of the order.
* @return int|bool insert id or false on failure.
*/
function wc_downloadable_file_permission( $download_id, $product, $order, $qty = 1 ) {
function wc_downloadable_file_permission( $download_id, $product, $order, $qty = 1, $item = null ) {
if ( is_numeric( $product ) ) {
$product = wc_get_product( $product );
}
@ -390,7 +391,7 @@ function wc_downloadable_file_permission( $download_id, $product, $order, $qty =
$download->set_access_expires( strtotime( $from_date . ' + ' . $expiry . ' DAY' ) );
}
$download = apply_filters( 'woocommerce_downloadable_file_permission', $download, $product, $order, $qty );
$download = apply_filters( 'woocommerce_downloadable_file_permission', $download, $product, $order, $qty, $item );
return $download->save();
}
@ -420,7 +421,7 @@ function wc_downloadable_product_permissions( $order_id, $force = false ) {
$downloads = $product->get_downloads();
foreach ( array_keys( $downloads ) as $download_id ) {
wc_downloadable_file_permission( $download_id, $product, $order, $item->get_quantity() );
wc_downloadable_file_permission( $download_id, $product, $order, $item->get_quantity(), $item );
}
}
}