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'] );
|
$loop = intval( $_POST['loop'] );
|
||||||
$file_counter = 0;
|
$file_counter = 0;
|
||||||
$order = wc_get_order( $order_id );
|
$order = wc_get_order( $order_id );
|
||||||
$items = $order->get_items();
|
|
||||||
|
|
||||||
|
if ( ! $order->get_billing_email() ) {
|
||||||
|
wp_die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
$items = $order->get_items();
|
||||||
|
|
||||||
|
// Check against order items first.
|
||||||
foreach ( $items as $item ) {
|
foreach ( $items as $item ) {
|
||||||
$product = $item->get_product();
|
$product = $item->get_product();
|
||||||
if ( ! in_array( $product->get_id(), $product_ids, true ) ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$files = $product->get_downloads();
|
|
||||||
|
|
||||||
if ( ! $order->get_billing_email() ) {
|
if ( $product && $product->exists() && in_array( $product->get_id(), $product_ids, true ) && $product->is_downloadable() ) {
|
||||||
wp_die();
|
$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( $files ) ) {
|
if ( ! empty( $download_data['files'] ) ) {
|
||||||
foreach ( $files as $download_id => $file ) {
|
foreach ( $download_data['files'] as $download_id => $file ) {
|
||||||
$inserted_id = wc_downloadable_file_permission( $download_id, $product->get_id(), $order, $item->get_quantity(), $item );
|
$inserted_id = wc_downloadable_file_permission( $download_id, $product->get_id(), $order, $download_data['quantity'], $download_data['order_item'] );
|
||||||
if ( $inserted_id ) {
|
if ( $inserted_id ) {
|
||||||
$download = new WC_Customer_Download( $inserted_id );
|
$download = new WC_Customer_Download( $inserted_id );
|
||||||
$loop ++;
|
$loop ++;
|
||||||
|
|
Loading…
Reference in New Issue