Create and sell license key in WooCommerce

Introduction

I decided to activate the license key at the time of selling the service in WooCommerce, enter the license key for the user, and release the restriction. I think that it can be applied to theme sales and plug-in sales.

Plugins

Use the following plugins

Sale

700万以上サイトで有効化中

License key management

1,000以上サイトで有効化中

Also, I developed the following two plug-ins that mediate the above two plugins.

Issue license key in WooCommerce

Embed a shortcode form to activate / deactivate the license key

Actual flow

Create a Product in WooCommerce

Product settings

Product data is Simple product and checks Virtual. Also, check Add License Key and set the following values.

  • Max allowed domains : Number of domains/installs in which this license can be used.
  • Expiry days : Expiry date of license. This is not the expiration date of the license itself, but the expiration date of the certification. If you have been authenticated before the deadline, the license will continue after the deadline.

Confirm the key on the setting screen of Software License Manager

Software License Manager setting screen
  • Secret Key for License Creation is the original key for creating a license key each time.

Configure Software License Manager for WooCommerce

Software License Manager for WooCommerce setting screen
  • License Server URL : URL of the server where Software License Manager runs. This works on another server too. By default, the URL of the same server is input.
  • Secret Key for License Creation : Enter the same one as the Software License Manager.

Product purchase screen and email

Product purchase screen
Email when purchasing a product
  • When a customer purchases a product, a license key is added to the purchase screen and email.

Orders

Orders screen
  • You can check the license key from the orders screen.

License key authentication on the client side

On the client side, use Software License Manager Client. Use the shortcode in post or page, or write it in a plugin or theme.

Software License Manager setting screen
  • Secret Key for License Verification Requests is a key for authentication. It authenticates with the license key and this key.

Configure Software License Manager Client

Software License Manager Client setting screen
  • There is a management screen, but you can incorporate it into a plug-in or theme as a library. In that case, copy “license-checker/class-slmclient.php” and “license-checker/jquery.slmclient.js” to plugins and themes, and use them as follows.
/* Change * Please rewrite the URL to read javascript. */
class-slmclient.php line 46
$this->script_url = *********** . 'license-checker/jquery.slmclient.js';

/* Sample 1 If you write without attributes, the values set in the management screen will be used. */
if ( ! class_exists( 'SlmClient' ) ) {
	require_once dirname( __FILE__ ) . 'class-slmclient.php';
}
echo do_shortcode('[slmcl]');

/* Sample 2 If an attribute is added and written, that value is prioritized and the value set in the management screen is ignored. */
if ( ! class_exists( 'SlmClient' ) ) {
	require_once dirname( __FILE__ ) . 'class-slmclient.php';
}
echo do_shortcode('[slmcl item_reference="test_plugin" sales_site_url="https://test.com/product/test2/" license_server_url="https://test.com/" special_secretkey="5d1291a361ef14.63243498"]');
  • The attributes of the shortcode are as follows.
    • item_reference : Is the name. Once the license has been activated, the option table is written with the name license_key_*** and the contents of the license key. For example, if item_reference is test, it will be license_key_test. To check for licenses from plugins or themes, just check for the presence of this option table with get_option. In the management screen, it corresponds to Name.
    • sales_site_url : Product URL of the WooCommerce shopping site. Corresponds to the Purchase button in the form. In the management screen, it corresponds to Sales Site URL.
    • license_server_url : URL of the server where Software License Manager runs. This works on another server too. By default, the URL of the same server is included. In the management screen, this corresponds to the License Server URL.
    • special_secretkey : It is Secret Key for License Verification Requests in the setting screen of Software License Manager. In the management screen, it corresponds to Special Secret Key for License.
  • It also provides an action hook for deactivating license keys.
/* Sample 1 If you write without array, it uses the value set in the management screen. */
do_action( 'deactive_slm_key', $arg = array() );

/* Sample 2 If an array is added and written, that value will be prioritized and the value set in the management screen will be ignored. */
$arg = array( 'item_reference' => 'test_plugin', 'sales_site_url' => 'https://test.com/product/test2/', 'license_server_url' => 'https://test.com/', 'special_secretkey' => '5d1291a361ef14.63243498' );
do_action( 'deactive_slm_key', $arg );
  • The attribute values of the action hook array are the same as the shortcode attribute values above.

License activation

Actually, below is the authentication screen of the plugin incorporating the short code. ※ The plugin is Add Mulitple User.

  • Enter the license key sent by email and activate it with the Activate button.
  • Send the License Key and press the Confirm button to confirm.
  • Once certified, the License Key will remain displayed.

License management on the server side

If you look at the Manage Licenses screen of Software License Manager, you can see that there is a License Key and the Status is active.

Results

I applied this system to the following plugins and web services.


Comments

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください