License Manager for WooCommerce

Easily sell and manage software license keys through your shop

lmfwc_get_license_meta()

function lmfwc_get_license_meta(int $licenseId, string $metaKey, bool $single = false)

Description

Retrieves a license meta field for the given license ID.

Parameters

$licenseId

(int) (Required) License ID.

$metaKey

(string) (Required) The meta key to retrieve.

$single

(mixed) (Required) (bool) (Optional) If true, returns only the first value for the specified meta key. This parameter has no effect if $key is not specified.

Default value: false

Return value

(mixed|false) Will be an array if $single is false. Will be value of the meta field if $single is true. Will be false on failure.

Source

File: /includes/functions/lmfwc-meta-functions.php

/**
 * Retrieves one or multiple license meta values
 *
 * @param int    $licenseId License Key ID
 * @param string $metaKey   Meta key to search by
 * @param bool   $single    Return a single or multiple rows (if found)
 *
 * @return mixed|mixed[]|bool
 */
function lmfwc_get_license_meta($licenseId, $metaKey, $single = false)
{
    $license = LicenseResourceRepository::instance()->find($licenseId);

    if (!$license) {
        return false;
    }

    if ($single) {
        /** @var LicenseMetaResourceModel $licenseMeta */
        $licenseMeta = LicenseMetaResourceRepository::instance()->findBy(
            array(
                'license_id' => $licenseId,
                'meta_key' => $metaKey
            )
        );

        if (!$licenseMeta) {
            return false;
        }

        return $licenseMeta->getMetaValue();
    }

    $licenseMetas = LicenseMetaResourceRepository::instance()->findAllBy(
        array(
            'license_id' => $licenseId,
            'meta_key' => $metaKey
        )
    );
    $result = array();

    /** @var LicenseMetaResourceModel $licenseMeta */
    foreach ($licenseMetas as $licenseMeta) {
        $result[] = $licenseMeta->getMetaValue();
    }

    return $result;
}