Created
March 15, 2021 14:36
-
-
Save ajgagnon/39c342d644558fe821d52a0ff989382d to your computer and use it in GitHub Desktop.
Fix licensing serving through woo-sl-licensing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter('WOOSL/API/get_downloadable_product_permission', function($permission, $download_id, $order_id) { | |
| global $wpdb; | |
| if (!$permission) { | |
| if (!function_exists('wcs_get_subscriptions_for_order')) { | |
| return $permission; | |
| } | |
| $sub_order = wcs_get_subscriptions_for_order($order_id); | |
| // if we don't have a subscription do regular | |
| if (empty($sub_order)) { | |
| return $permission; | |
| } | |
| // get subscription ids | |
| $sub_order_ids = array_keys($sub_order); | |
| // if we have some, get permission based on this order id | |
| if (!empty($sub_order_ids[0])) { | |
| $mysql_query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions | |
| WHERE download_id = %s AND order_id = %d | |
| ", $download_id, $sub_order_ids[0]); | |
| $permission = $wpdb->get_row( $mysql_query ); | |
| } | |
| } | |
| return $permission; | |
| }, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment