-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add $item to wc_downloadable_file_permission #23188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adding the parameter `$item` to both the function `wc_downloadable_file_permission` and the filter hook `woocommerce_downloadable_file_permission` would provide a further level of customization for the downloadable file being granted, depending on the metadata assigned to the single item when purchasing a product.
|
I fully tested this on a local website I am currently developing and everything is working as expected. Scenario: MUSIC LICENSING WEBSITE Since I want to avoid all this, especially considering that the client who is going to deal with the backend of the website is not a developer himself, I came up with an idea that is proving absolutely rock solid when it comes to operability and simplicity. The music tracks are added as items of a custom post type The most important reason I came up with this idea is that: When a user clicks on the BUY button corresponding to a track, a dialog pops up, letting the user choose the variation they need. When finally added to the cart, a script adds the selected variation to the cart, adding the Since neither the product nor its variations have downloadable files associated to them, the whole process of permission granting happens programmatically, through the filter Simply adding the Other filters involved in this whole process are: I hope this is clear enough and makes sense. |
claudiosanches
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like that is missing this $item implementation in WC_AJAX::grant_access_to_download.
|
@claudiosanches, you are absolutely right. $order = wc_get_order( $order_id );
[...]
foreach ( $order->get_items() as $item ) {
$product = $item->get_product();
[...]
$downloads = $product->get_downloads();
foreach ( array_keys( $downloads ) as $download_id ) {
wc_downloadable_file_permission( $download_id, $product, $order, $item->get_quantity() );
[...]If the same mechanism could be used, the function $order_id = intval( $_POST['order_id'] );
$loop = intval( $_POST['loop'] );
$file_counter = 0;
$order = wc_get_order( $order_id );
foreach ( $order->get_items() as $item ) {
$product = $item->get_product();
$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_id, $order, $item->get_quantity(), $item );
if ( $inserted_id ) {
$download = new WC_Customer_Download( $inserted_id );
$loop ++;
$file_counter ++;
if ( $file->get_name() ) {
$file_count = $file->get_name();
} else {
/* translators: %d file count */
$file_count = sprintf( __( 'File %d', 'woocommerce' ), $file_counter );
}
include 'admin/meta-boxes/views/html-order-download-permission.php';
}
}
}
} |
Adding $item to wc_downloadable_file_permission would make `grant_access_to_download` compatible with the changes in woocommerce#23188
|
HERE you can find a possible change to |
|
@LuigiPulcini in this case we use Still for what you are trying to do seems like that could alternate this methods or even create a new one, passing the Those are the solutions that I can think of, still both requires code refactor. |
|
Thanks for your inputs, @claudiosanches Regarding the $product_ids, we could use both methods at the same time, allowing developers to send a list of $product_ids within the AJAX call and, if that parameter is left unset, use all the $product_ids linked to the specific order. That would not affect the possibility to add the $item to the Actually, I have a working installation where, after applying the proposed changes, everything works flawlessly and as expected. From what I can see, this refactor would already be enough to keep the functions consistent with the current implementation, while opening them to the new approach. |
|
This is still not good to merge, since all occurrences of |
|
Hi, @claudiosanches The function What would you recommend? Using this PR or creating a new one with all the file changes required? |
|
@LuigiPulcini better put all in just one PR, since it's for the same reason. Like I said, no problem including a new parameter on it, but we need to make it consistent. Thanks for your help! |
|
@LuigiPulcini Just checking if you saw @claudiosanches last comment and if you are still willing to make the changes so we can get this merged? |
|
Closing due to inactivity. Please leave a comment if you still plan to work on this and we will reopen. Thanks. |
Please refer to woocommerce#23188 for the whole conversation about this.
Please refer to woocommerce#23188 for the whole conversation about this.
|
First of all, sorry for the mess with the commits. :) These new commits include the changes to the class-wc-ajax.php that @claudiosanches recommended at the beginning of this conversation. The main change to the This should complete the adjustments requested above. Let me know if this can work for you. Best, |
|
Hi, @claudiosanches Thanks, |
|
I am wondering if it is possible to move forward with this PR. Thanks! |
|
@LuigiPulcini If you merge the current version of master into the PR you will trigger a Travis build. The build that failed is on travis.org and we cannot restart it because the project was moved to use travis.com. |
claudiosanches
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you very much!
…duct id With the PR woocommerce#23188, "$product_id" variable become undefined.
…duct id With the PR #23188, "$product_id" variable become undefined.
All Submissions:
Changes proposed in this Pull Request:
Adding the parameter
$itemto both the functionwc_downloadable_file_permissionand the filter hookwoocommerce_downloadable_file_permissionwould provide a further level of customization for the downloadable file being granted, depending on the metadata assigned to the single item when purchasing a product.How to test the changes in this Pull Request:
woocommerce_downloadable_file_permission, including 5 parameters$itemto verify that it is passed the data of the single item in each orderOther information:
Changelog entry
Added parameter
$item(instance of WC_Order_Item) to both the functionwc_downloadable_file_permissionand the filter hookwoocommerce_downloadable_file_permission