Skip to content

Instantly share code, notes, and snippets.

@stephywells
Created July 12, 2015 03:17
Show Gist options
  • Save stephywells/4a761cc3a37f7ab5a9d8 to your computer and use it in GitHub Desktop.
Save stephywells/4a761cc3a37f7ab5a9d8 to your computer and use it in GitHub Desktop.
Allow all downloads in a EDD bundle to use a sinle license
<?php
/**
* Allow multiple downloads in a bundled Easy Digital Downloads
* product be updated from a single license
* 1. Create 1 download set to generate a license
* 2. Create more downloads and do not set them to generate licenses
* 3. Create one more download and bundle all the downloads from #1 and #2
*/
function s11_allow_single_license() {
if ( isset( $_POST['item_id'] ) && isset( $_POST['item_name'] ) && isset( $_POST['license'] ) ) {
$license = sanitize_text_field( $_POST['license'] );
$download_id = edd_software_licensing()->get_download_by_license( $license );
$item_id = absint( $_POST['item_id'] );
if ( $download_id != $item_id ) {
// check if this product is in the same bundle
global $wpdb;
$query = $wpdb->prepare( 'SELECT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key = %s', '_edd_bundled_products' );
$bundle_download = $wpdb->get_col( $query );
$allow_download = false;
foreach ( $bundle_download as $bundle ) {
$bundle_ids = maybe_unserialize( $bundle );
$includes_both = array_intersect( array( $download_id, $item_id ), $bundle_ids );
if ( count( $includes_both ) >= 2 ) {
$allow_download = true;
break;
}
}
if ( $allow_download ) {
define( 'EDD_BYPASS_ITEM_ID_CHECK', true );
}
}
}
}
add_action( 'edd_get_version', 's11_allow_single_license', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment