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|string
Search arguments.
Returns
Returns a License Key data model or null
if no license key found.
Search arguments
Present arguments | Search 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 }
Or search by code directly:
$license_key = wc_find_license_key( '4asdsadefasf-45' );
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 $product
that 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.
wc_license_key_activate()
$response = wc_license_key_activate( $model_or_args );
Calls API “activate” endpoint and returns its response. This function is useful to activate license keys within the same WordPress setup.
Parameters
$model_or_args
LicenseKey|array
A LicenseKey
object model or an array
with a list of multiple parameters.
Returns
wc_license_key_validate()
$response = wc_license_key_validate( $model_or_args, $activation_id );
Calls API “validate” endpoint and returns its response. This function is useful to validate license key activations within the same WordPress setup.
Parameters
$model_or_args
LicenseKey|array
A LicenseKey
object model or an array
with a list of multiple parameters.
$activation_id
int
(OPTIONAL) Required only if $model_or_args
is a LicenseKey
object model.
Returns
Returns a WPMVC\Response
object.
wc_license_key_deactivate()
$response = wc_license_key_deactivate( $model_or_args, $activation_id );
Calls API “deactivate” endpoint and returns its response. This function is useful to deactivate license key activations within the same WordPress setup.
Parameters
$model_or_args
LicenseKey|array
A LicenseKey
object model or an array
with a list of multiple parameters.
$activation_id
int
(OPTIONAL) Required only if $model_or_args
is a LicenseKey
object model.
Returns
Returns a WPMVC\Response
object.