Filter changed, limit no of generated license keys for order
-
Hello,
I’m using the License Manager for WooCommerce plugin (great work by the way Drazen!) in a webshop where for any number of products in an order only one license key is needed (story: I sell a number of users licenses that can be activated on their accounts in my system with the same license key).
Therefore I’ve hooked to the lmfwc_create_license_keys filter on 2.0.1 version to limit the number of generated license keys to a single one like this:
function limitGeneratedLicenseKeys($params) {
$params[‘amount’] = 1;
return $params;
}
add_filter( ‘lmfwc_create_license_keys’, ‘limitGeneratedLicenseKeys’, 10);But after the update to 2.1.0 I had the surprise that this wasn’t working anymore, so I’ve checked the source code of LMFWC and saw that the filter name was changed to lmfwc_generate_license_keys with totally different parameters. So I’ve changed my hook like this:
function limitGeneratedLicenseKeys($amount, $generator, $licenses = array()) {
$new_licenses = array_slice($licenses, 0, 1);
return $new_licenses;
}
add_filter( ‘lmfwc_generate_license_keys’, ‘limitGeneratedLicenseKeys’, 25, 3);But there seems to be a problem that I can’t figure out how to fix, the licenses are actually in the first parameter $amount?! For now I’ve changed my code to array_slice the $amount parameter instead of $licenses. But I am very curious if anyone else is experiencing this and why it’s happening – going through LMFWC source code I didn’t notice any weird function arguments order change.
Also I have a suggestion for you Drazen, would be great to have an option built in the plugin to limit the number of generated license keys for an order so I don’t have to rely on these hacks that can break on a plugin update.
Thanks,
Mihail
- The topic ‘Filter changed, limit no of generated license keys for order’ is closed to new replies.