Merge pull request #23188 from LuigiPulcini/master
Add $item to wc_downloadable_file_permission
This commit is contained in:
commit
50e036f934
|
@ -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 ++;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue