Support » Plugin: Easy Digital Downloads - Simple eCommerce for Selling Digital Files » Selling files directly from a directory?

  • Resolved jamieburchell

    (@jamieburchell)


    Hi

    Suppose I have a directory on my server where PDF files are automatically generated by some external process periodically. Is it possible to use EDD to either allow purchasing of these PDFs or automatically import them for purchase in some way? Each PDF would be the same flat price. I’m assuming that in reality, each generated file would need to be added to a database for this to work?

    Suggestions welcome
    Cheers
    Jamie

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Mihai Joldis

    (@misulicus)

    Hey @jamieburchell

    You can use EDD to sell your existing PDF files. You would need to create the Download programmatically, using the EDD_Download class https://docs.easydigitaldownloads.com/article/1020-edddownload

    The other date from a Download is stored as post metadata so you need to add that separately. You can use the edd_download_post_create hook which runs after the “create()” method in the main EDD_Class to attach the metadata to the base download.

    On that edd_download_post_create hook you can run the code to add the metadata and you can look at this example in our test code as a starting point to add your other data like prices and to also link the downloadable files: https://github.com/awesomemotive/easy-digital-downloads/blob/master/tests/helpers/class-helper-download.php#L38-L63

    In the code example, you can see that the downloadable files are added in the $_download_files array and if your PDF files already exist on your server you can simply add the full URL to the file you want to provide as a downloadable.

    Regards

    Thread Starter jamieburchell

    (@jamieburchell)

    Thanks for taking the time to reply with that information.

    Although I’m familiar with PHP, I have little to no knowledge of WordPress development and its eco-system, short of adding the occasional filter or action. I understand the concept and the code you’ve provided, but I don’t know how to put it together. For example, where/how to hook into the create action and only for these automated uploads.

    It sounds like either way some sort of custom plugin would need to be created for this.

    Thread Starter jamieburchell

    (@jamieburchell)

    I’m assuming if I can get the download ID after using the create method, I can use this to add the meta without using the hook?

    Plugin Support Mihai Joldis

    (@misulicus)

    Hi @jamieburchell

    The ID of the download is available via the hook I mentioned earlier which is triggered at the end of the execution of the create() method: do_action( 'edd_download_post_create', $id, $args );

    You could alternatively use the example here https://github.com/awesomemotive/easy-digital-downloads/blob/master/tests/helpers/class-helper-download.php#L31-L63 to create a post by using the WordPress wp_insert_post function and you can create the Download in one go.

    I don’t know exactly how you are generating your PDF files at the moment but I am assuming you would want to run the Download creation right after a PDF file has been generated to create a Download and attach it.

    Thread Starter jamieburchell

    (@jamieburchell)

    Got it, thanks. I realise now that EDD_Download::create doesn’t return the post ID

    Thread Starter jamieburchell

    (@jamieburchell)

    Thanks for your help on this. I’m getting somewhere!

    When creating the download post manually using your example – are all of the parameters required? E.g. _edd_download_sales or are these created automatically as required?

    Plugin Support Mihai Joldis

    (@misulicus)

    Assuming you are creating a normal download (no variable pricing) I would just set:

    
    'edd_price'                         => '20.00',
    '_variable_pricing'                 => 0,
    'edd_variable_prices'               => false,
    'edd_download_files'                => array_values( $_download_files ),
    '_edd_product_type'                 => 'default',
    

    That should create a basic product with the price you set, non-variable, and the download files that you want to attach.

    • This reply was modified 6 months, 2 weeks ago by Mihai Joldis.
    Thread Starter jamieburchell

    (@jamieburchell)

    Brilliant, thanks very much.

    Plugin Support Mihai Joldis

    (@misulicus)

    Hi @jamieburchell

    Are you OK with me marking this topic as Resolved for now?

    Regards

    Thread Starter jamieburchell

    (@jamieburchell)

    Thank you for your help

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Selling files directly from a directory?’ is closed to new replies.