Support » Plugin: License Manager for WooCommerce » Filter changed, limit no of generated license keys for order

  • Resolved mihailj

    (@mihailj)


    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

    • This topic was modified 3 weeks, 1 day ago by mihailj. Reason: changed title
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @mihailj,

    thank you for your message and for using my plugin.

    I actually just realized, that the filter will never work the way it used to because I decided to split the variables into different function parameters. I will have to rethink this part.

    Let me just understand your scenario right: Every customer order in your webshop comes with a single license key, regardless of the product or its quantity. Then, this once license key is used to activate all of those products. Am I correct so far?

    Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @mihailj,

    do you still need help with this?

    Plugin Author Drazen Bebic

    (@drazenbebic)

    I’ll mark this as resolved, due to inactivity.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.