Support » Plugin: License Manager for WooCommerce » Overriding License Key

  • Resolved YeKen

    (@aliakro)


    Hi there,

    Me again, sorry! I’m looking through your plugin and trying to find the best place to override your generator (using a filter) to use my existing license key logic (saves me retro fitting my plugins).

    It appears updateLicenseKey() is the best place? I don’t suppose you could add a filter for $clean_license_key ?

    That way I can filter it with my own logic? Ideally, need the WooCommerce order ID passed to the filter too!

    Pretty please 🙂

    Ali

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @aliakro!

    I actually have planed to add this as a feature, but I can’t really be sure when it’s coming out. Eventually though, you’ll be able to implement your own license key generation logic inside a filter.

    For now, let’s see…

    There’s a filter in the Generator class called lmfwc_generate_license_string, it’s the one that generates ALL license keys from all generators, based on the input parameters. Maybe you’d want to try that?

    Here’s the source file:

    https://plugins.trac.wordpress.org/browser/license-manager-for-woocommerce/trunk/includes/Generator.php

    Thank you… would be a brilliant feature!

    I did look at that filter, but ideally, I’d have the order ID (I’m going to generate the license based on some of the data associated with the order).

    I maybe able to use that filter if I can get easily, from Woocomerce, the last order ID for the user 🙂

    Thanks again for you help!

    Plugin Author Drazen Bebic

    (@drazenbebic)

    @aliakro

    The good old Order ID… 😀

    Let’s see, what about this file?

    https://plugins.trac.wordpress.org/browser/license-manager-for-woocommerce/trunk/includes/OrderManager.php

    specifically this hook: lmfwc_insert_generated_license_keys

    That something you could work with?

    So presuming I only had one license per order (which I do), I could filter $licenses[‘licenses’][0] ?

    Replace the value in that and encrypt it?

    Ah looking at it again, that looks like the right place… I don’t need to do the encryption… just modify the array of licenses 🙂

    Plugin Author Drazen Bebic

    (@drazenbebic)

    @aliakro,

    give it a go and let me know how it turns out 🙂

    Ah it may not work 🙁

    I think it’s the way you use filters for lmfwc_insert_generated_license_keys. You don’t actually allow the filter to return something. You use apply_filters() to call a function and pass the arguments – not sure this is really the intended way of using filters?

    Although I can apply a filter to the licenses, I’ve no ability to return the data as your apply_filter() call doesn’t expect a return value?

    `function yeken_license_override( $order_id, $product_id, $licenses, $expires_in ) {

    $licenses[0] = ‘TEST LICENSE’;

    // What do I return here?

    }
    add_filter( ‘lmfwc_insert_generated_license_keys’, ‘yeken_license_override’, 10, 4 );

    Thinking I may fork your plugin slightly for my needs 😛

    Could you perhaps put this on the line above? That way the $licenses array can be manipulated and returned pre-save? Pretty please 🙂

    $licenses = apply_filters(
    							'lmfwc_pre_insert_generated_license_keys',
    							$licenses,
    							$order_id,
    		                    $product->get_id(),
    							$generator
                );
    Plugin Author Drazen Bebic

    (@drazenbebic)

    Hello @aliakro,

    sorry I’ve been a bit busy the last two days.

    Yes, I will include this in the next update, absolutely no problem! 🙂

    Ah great stuff.. thanks 🙂

    Quick question…was this functionality implemented in the version 2.0 release?

    Plugin Author Drazen Bebic

    (@drazenbebic)

    @ryanaripley,

    do you mean the custom generators? If so, then sadly not. However, the next feature update (2.1.0) will include them. I have already started working on this and other features for 2.1.0, so it shouldn’t take too long.

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