Uploading ebooks into WooCommerce and WordPress

I've helped set up a number of WordPress-based commerce sites for authors. One of the first things that always gets in the way is the inability to upload MOBI or EPUB file into WooCommerce to actually set the books.

To get around this is a pretty simple process.

  1. In wp-content/plugins, create a directory like local-upload-ebooks.
  2. Create local-upload-ebooks/local-upload-eboooks.php and edit it.
  3. Put the text below into it and save it.
  4. Go into your Plugin Manager and enable the plugin.
<?php
/*
 Plugin Name: Upload Ebooks
 Version: 0.0.0
 Author: D. Moonfire
 Description: Enables uploading ebooks into WordPress and WooCommerce.
*/

// Add in a hook to add the taxonomies and categories.
add_action('init', 'upload_ebook_init', 0);

function upload_ebook_init()
{
  // This allows up to add the MIME types that can be uploaded.
  add_filter('upload_mimes', 'upload_ebook_upload_mimes');

  // These are completely arbitrary and probably too big.
  ini_set('upload_max_size','100M');
  ini_set('post_max_size','99M');

  // Ebooks sometimes take a little longer to upload.
  ini_set('max_execution_time','300');
}

function upload_ebook_upload_mimes($mimes)
{
  $mimes = array_merge($mimes, array(
    'epub' => 'application/epub+zip',
    'mobi' => 'application/x-mobipocket-ebook'
  ));

  return $mimes;
}
?>

I hope it helps anyone who gets stuck by this. I'm sure there is already a plugin in WordPress's catalog, I just couldn't find it.

Metadata

Categories:

Tags: