I definitely need multiple downloads per product in MarketPress. E.g. several songs in a music store belong to an album or a collection.
I studied the plugin and found it is possible with an afternoon’s work to build it in. Here are the steps to do it:
1a. The idea is, to store in the mp_file field of a product not one, but all URLs you want to include in the product.
1b. So you have to make the field bigger on the screen to show all these URLs (one at a line)
1c. To do so in file marketpress/marketpress.php you change the input text field with name mp_file into a textarea with 100 cols and 7 rows
1d. In the same file search for update_post_meta( $post_id, ‘mp_file’ … ) and put some code in to transform the lines from the input field into a string, where the URLs are separated by comma. This avoids any problems with newlines interpreted as spaces etc.
Now we have several URLs stored in the mp_file field of a product.
2. Whereever the mp_file field is used to generate an URL for downloading one product you change the code so it deals with several URLs:
2a. in marketpress/marketpress.php change the function get_download_url so that it returns an array of URLs (and not a single URL). To make the URLs different from each other I decided to add a GET parameter (named “file”:wink: with the number of the URL in the array. This way it interferes the least with the existing method of identifying a download with the product.
2b. In the function serve_download you have to ask the GET parameter “file” to find out which URL to serve for download.
This function also checks how often a file was already downloaded. This is more difficult to implement for each of the URLs of one product – it means extending the data structure of $download array. I decided against it. Instead of I test if there has been more then (max_downloads * number of files for the product) downloads. That means each file could be downloaded the maximum of permitted downloads (or more, if another file is downloaded right away on the first try).
When the file is served marketpress generates a filename for it. To make a different name for each of the files of one product you have to add the number of the file to this filename (search for sanitize_file_name).
2c. The confirmation email must have download links for all files of the product. This is added in the function filter_email.
3. The order status, which can be inspected on the store web page contains the download link. The code for this has to be extended so all download links for all files for one product appear.
3a. There is a file marketpress/marketpress-includes/template-functions.php where you can find useful functions for themes. Searching for “Download” leads you to a table where the link is printed (if the order is paid and the download limit is not exceeded). There you have to make the same adaptions as described above for computation of the download limit and for generating the download links.
4. It should also work with your theme, shouldn’t it? I use the child theme gridmarket of FrameMarket. The only way to get it really working with this theme was to change the file framemarket/library/functions/marketpress.php (I could not figure out how to do this in the child theme): Search for a table followed by an “if ($order_paid)”. There you have to add the max download test and the generation of the download links – it is the very same as you might have done in the template-functions.php file.
That’s it. Screenshots of the result you can see in the first answer (can still not figure out how to include pics in the opening post).
I have to clean up the comments a bit and migrate completely to Marketpress 2.8.1 (I started in 2.8 with it). Then I can give the files to whoever might be interested in this (not before friday).