1. Home
  2. Docs
  3. WooCommerce License Keys
  4. Developers
  5. Functions Reference

Functions Reference

Reference to global functions you can use:


wc_find_license_key()

$license_key = wc_find_license_key( $args );

Finds and returns a license key data model with based on given search arguments This function already applies filter woocommerce_license_key.

Parameters

$args
array
Search arguments.

Returns

Returns a License Key data model or null if no license key found.

Search arguments

Present argumentsSearch description
$arg[‘code’]Searches a license key based on a customer code.
$arg[‘order_item_id’, ‘ code ‘] Searches a license key based on an order item id and a code.
$arg[‘meta_id’]Searches a license key based on an order item meta id. Only on the extended plugin.

Example

$license_key = wc_find_license_key( ['code' => '4asdsadefasf-45'] );

if ( $license_key ) {
    // License key exists, do something
}

wc_get_license_key()

$license_key = wc_get_license_key( $customer_code );

Finds and returns a license key data model with a given customer’s license key code. This function already applies filter woocommerce_license_key.

Parameters

$customer_code
string
Customer’s license key code.

Returns

Returns a License Key data model or null if no license key found.

Example

$license_key = wc_get_license_key( '4asdsadefasf-45' );

if ( $license_key ) {
    // License key exists, do something
}

wc_is_license_key()

if ( wc_is_license_key( $product_or_type ) ) {
    // Do something
}

Returns a flag indicating if a product is based on a license key. This function can be also used on subscription-based products that support license keys.

If not parameter is used, the function will look for the global variable $productthat it is usually initialized on the product’s page.

Parameters

$product_or_type
WC_Product|string
A WC_Product object or a string with the product type identifier. (Optional)

Returns

Returns a bool value flag indicating if the product tor type is based on a license key.

Was this article helpful to you? Yes No