License Manager for WooCommerce

Easily sell and manage software license keys through your shop

lmfwc_add_license_meta()

function lmfwc_add_license_meta(int $licenseId, string $metaKey, mixed $metaValue)

Description

Adds a meta field to the given license.

Parameters

$licenseId

(int) (Required) License ID.

$metaKey

(string) (Required) Metadata name.

$metaValue

(mixed) (Required) Metadata value. Must be serializable if non-scalar.

Return value

(mixed|false) Meta value on success, false on failure.

Source

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

/**
 * Adds a new entry to the license meta table.
 *
 * @param int    $licenseId License Key ID
 * @param string $metaKey   Meta key to add
 * @param mixed  $metaValue Meta value to add
 *
 * @return mixed|bool
 */
function lmfwc_add_license_meta($licenseId, $metaKey, $metaValue)
{
    $license = LicenseResourceRepository::instance()->find($licenseId);

    if (!$license) {
        return false;
    }

    /** @var LicenseMetaResourceModel $licenseMeta */
    $licenseMeta = LicenseMetaResourceRepository::instance()->insert(
        array(
            'license_id' => $licenseId,
            'meta_key'   => $metaKey,
            'meta_value' => maybe_serialize($metaValue)
        )
    );

    if (!$licenseMeta) {
        return false;
    }

    return $licenseMeta->getMetaValue();
}