• Resolved mahdih24

    (@mahdih24)


    Hi,
    I’m using your plugin License Manager for WooCommerce, and I need to display decrypted license keys for the currently logged-in user using a custom shortcode or a standalone plugin.

    However, I’m having trouble accessing the decrypted license values outside your plugin (in a custom shortcode). Could you please help clarify a few things?

    1. What is the correct full path and filename of the class that handles license decryption?
      (Specifically, the one that contains the getDecryptedLicenseKey() method.)
    2. How can I properly include or autoload this class from outside the plugin?
      For example, should I require a specific file like vendor/autoload.php, or is there a central file that sets up autoloading for all classes?
    3. Is it safe to instantiate and use the license model directly from outside the plugin like this?
    $license = new LicenseManagerForWooCommerce\Models\Resources\License($id);
    $license_key = $license->getDecryptedLicenseKey();

    Or is there a different recommended way to fetch and decrypt a license by its ID?

    • 4. Are there any requirements or dependencies needed for license decryption to work correctly?
      (e.g., encryption keys, user context, WooCommerce session, admin environment, etc.)
    • I’m building this as a separate plugin to avoid overwriting anything during updates.
    • Your guidance would be much appreciated 🙏
    • Thanks in advance!
Viewing 1 replies (of 1 total)
  • Plugin Support muddasirhayat

    (@muddasirhayat)

    Hi @mahdih24,

    Thank you for contacting us. We hope you are doing well.

    To retrieve and decrypt license keys programmatically, you can use the following approach:

    add_action( 'your_tag_name', function() {
    use LicenseManagerForWooCommerce\Repositories\Resources\License as LicenseResourceRepository;

    $licenses = LicenseResourceRepository::instance()->findAllBy([
    'order_id' => $order_id,
    'product_id' => $product_id,
    ]);

    $get_licenses = [];
    foreach ($licenses as $license) {
    $get_licenses[] = $license->getDecryptedLicenseKey();
    }

    } );

    Regarding your questions:

    1. The class that contains the getDecryptedLicenseKey() method is located at:
      /wp-content/plugins/license-manager-for-woocommerce/app/Models/Resources/License.php
    2. The plugin uses Composer for autoloading. If the plugin is active, all classes are autoloaded automatically. You do not need to include a separate autoload file.
    3. We recommend using the repository method rather than instantiating the model directly. Using
    LicenseResourceRepository::instance()->findAllBy([...]);

    is the preferred way, as it ensures proper context and loading.

    1. To decrypt licenses, the plugin must be active and the encryption keys configured during setup must be intact. You do not need an admin session, but make sure the code is executed after plugins are loaded.

    Let us know if you need further assistance.

    Thanks & Regards,
    WP Experts Support Team

Viewing 1 replies (of 1 total)

The topic ‘Question about using LicenseManagerForWooCommerce programmatically’ is closed to new replies.