License Manager for WooCommerce

Easily sell and manage software license keys through your shop


function lmfwc_update_license_meta(int $licenseId, string $metaKey, mixed $metaValue, mixed $previousValue = null)


Updates a license meta field based on the given license ID. Use the $prev_value parameter to differentiate between meta fields with the same key and license ID. If the meta field for the license does not exist, it will be added and its value returned. Can be used in place of lmfwc_add_license_meta().



(int) (Required) License ID.


(string) (Required) Metadata name.


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


(mixed) (Optional) Previous value to check before updating.

Default value: null

Return value

(bool) True on success, false on failure.


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

 * Updates existing license meta entries.
 * @param int    $licenseId
 * @param string $metaKey
 * @param mixed  $metaValue
 * @param mixed  $previousValue
 * @return bool
function lmfwc_update_license_meta($licenseId, $metaKey, $metaValue, $previousValue = null)
    $license = LicenseResourceRepository::instance()->find($licenseId);

    if (!$license) {
        return false;

    $selectQuery = array(
        'license_id' => $licenseId,
        'meta_key'   => $metaKey
    $updateQueryCondition = array(
        'license_id' => $licenseId,
        'meta_key'   => $metaKey
    $updateQueryData = array(
        'license_id' => $licenseId,
        'meta_key'   => $metaKey,
        'meta_value' => maybe_serialize($metaValue)

    if ($previousValue !== null) {
        $selectQuery['meta_value'] = $previousValue;
        $updateQueryCondition['meta_value'] = $previousValue;

    $metaLicense = LicenseMetaResourceRepository::instance()->findBy($selectQuery);

    if (!$metaLicense) {
        return false;

    $updateCount = LicenseMetaResourceRepository::instance()->updateBy($updateQueryCondition, $updateQueryData);

    if (!$updateCount) {
        return false;

    return true;