Skip to content

Instantly share code, notes, and snippets.

@robertuniqid
Last active August 5, 2022 14:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertuniqid/3ea16245e3e4b28a2d4ff78e99757540 to your computer and use it in GitHub Desktop.
Save robertuniqid/3ea16245e3e4b28a2d4ff78e99757540 to your computer and use it in GitHub Desktop.
EDD - Bundle License to emulate the normal licenses.
<?php
add_action( 'init', function() {
if( !isset( $_GET['edd_action'] ) && !isset( $_POST['edd_action'] ) )
return;
if( !isset( $_GET[ 'license' ] ) || !isset( $_GET[ 'item_id' ] ) )
if( !isset( $_POST[ 'license' ] ) || !isset( $_POST[ 'item_id' ] ) )
return;
if( !class_exists( 'EDD_Software_Licensing' ) )
return;
$license = ( isset( $_GET[ 'license' ] ) ? $_GET[ 'license' ] : $_POST[ 'license' ] );
$item_id = ( isset( $_GET[ 'item_id' ] ) ? $_GET[ 'item_id' ] : $_POST[ 'item_id' ] );
$license_information = EDD_Software_Licensing::instance()->get_license( $license, true );
if( !is_object( $license_information->download ) )
return;
if( !$license_information->download->is_bundled_download() )
return;
$find_child_license = get_posts( [
'post_parent' => $license_information->ID,
'post_type' => 'edd_license',
'posts_per_page' => -1,
'post_status' => 'any',
'meta_key' => '_edd_sl_download_id',
'meta_value' => intval( $item_id )
] );
if( empty( $find_child_license ) )
return;
$find_child_license = array_shift( $find_child_license );
$new_license = get_post_meta( $find_child_license->ID, '_edd_sl_key', true );
if( $new_license == '' )
return;
$request_filter = function( $response, $args, $license_id ) use ( $license_information ) {
$response['bundled_products'] = $license_information->download->get_bundled_downloads();
return $response;
};
add_filter( 'edd_remote_license_check_response', $request_filter, 20, 3 );
add_filter( 'edd_remote_license_activation_response', $request_filter, 20, 3 );
if( isset( $_GET['license'] ) )
$_GET['license'] = $new_license;
if( isset( $_POST['license'] ) )
$_POST['license'] = $new_license;
}, 9 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment