Allows set downloadable permissions to any downloadable product in any order
This commit is contained in:
parent
63fe943ef9
commit
886abe282d
|
@ -795,22 +795,43 @@ class WC_AJAX {
|
|||
$loop = intval( $_POST['loop'] );
|
||||
$file_counter = 0;
|
||||
$order = wc_get_order( $order_id );
|
||||
$items = $order->get_items();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
if ( ! empty( $files ) ) {
|
||||
foreach ( $files as $download_id => $file ) {
|
||||
$inserted_id = wc_downloadable_file_permission( $download_id, $product->get_id(), $order, $item->get_quantity(), $item );
|
||||
$data = array();
|
||||
$items = $order->get_items();
|
||||
|
||||
// Check against order items first.
|
||||
foreach ( $items as $item ) {
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( $product && $product->exists() && in_array( $product->get_id(), $product_ids, true ) && $product->is_downloadable() ) {
|
||||
$data[ $product->get_id() ] = array(
|
||||
'files' => $product->get_downloads(),
|
||||
'quantity' => $item->get_quantity(),
|
||||
'order_item' => $item,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $product_ids as $product_id ) {
|
||||
$product = wc_get_product( $product_id );
|
||||
|
||||
if ( isset( $data[ $product->get_id() ] ) ) {
|
||||
$download_data = $data[ $product->get_id() ];
|
||||
} else {
|
||||
$download_data = array(
|
||||
'files' => $product->get_downloads(),
|
||||
'quantity' => 1,
|
||||
'order_item' => null,
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $download_data['files'] ) ) {
|
||||
foreach ( $download_data['files'] as $download_id => $file ) {
|
||||
$inserted_id = wc_downloadable_file_permission( $download_id, $product->get_id(), $order, $download_data['quantity'], $download_data['order_item'] );
|
||||
if ( $inserted_id ) {
|
||||
$download = new WC_Customer_Download( $inserted_id );
|
||||
$loop ++;
|
||||
|
|
Loading…
Reference in New Issue