Kadence Tutorial: Selling Kadence Pattern Hub Access Keys in WooCommerce

in using Kadence When Pattern Hub is used, you can generate access keys for the design library and provide access to others. If you intend to access the library via the WooCommerce Selling these access keys requires the use of more powerful tools to generate and manage the keys.The WooCommerce Software License Plugin and License Manager for WooCommerce plugin are ideal solutions. In this article, we will introduce thistwoThe basic setup of the plug-in and how it integrates with the Kadence Pattern Hub for access key sales.

Image [1]-Complete Guide to Selling Kadence Pattern Hub Access Keys in WooCommerce

Step 1: Create a Pattern Hub Access Product

First, in the WooCommerce Create a new product in which the product will be used to sell access keys. Set up the product as a virtual product without using the shipping process.

  • Creating Virtual Products
    go into WordPress Backstage, select WooCommerce -> Products -> Add New Product, and set up as a virtual product.
Image [2]-Complete Guide to Selling Kadence Pattern Hub Access Keys in WooCommerce
  • Configuration License
    Depending on the plug-in used (WooCommerce Software License or License Manager for WooCommerce), set the license configuration for the product and associate it with the Access Key Generator.
Image [3]-Complete Guide to Selling Kadence Pattern Hub Access Keys in WooCommerce
WooCommerce Software License(WooCommerce Software License)
Image [4]-Complete Guide to Selling Kadence Pattern Hub Access Keys in WooCommerce
WooCommerce License Manager(License Manager for WooCommerce)

Step 2: Connect Kadence Pattern Hub to License Validation

exist WooCommerce After selling an access key in Kadence Pattern Hub, you need to ensure that Kadence Pattern Hub can verify the validity of the license. To do this, you need to add a custom PHP Filter.

WooCommerce Software License Filter Settings::

The following snippet will check if the license is valid and activated for the requested domain at the time of the request. If the key is valid and activated, access is returned as allowed.

/**
 * Validates license with WooCommerce Software License.
 *
 * @param Boolean         $access true or false based on access.
 * @param String          $key the access key.
 * @param WP_REST_Request $request full details about the request.
 * @return Boolean based on if access should be granted.
 */
function custom_check_cloud_access( $access, $key, $request ) {
	// If true the key matches with settings in Kadence Pattern Hub. Let that pass for testing purposes.
	if ( $access ) {
		return $access;
	}
	// Make sure WooCommerce Software License exists.
	global $WOO_SL_API;
	if ( $WOO_SL_API ) {
		$site = preg_replace('(^https?://)', '', $request->get_param( 'site' ) );
		$args =   array(
			'licence_key'       => $key,
			'domain'            => $site,
			'woo_sl_action'     => 'status-check',
			'product_unique_id' => 'PRODUCT_UNIQUE_ID',
		);
		$response = $WOO_SL_API->API_call( $args );
		$response = json_decode( $response );
		end( $response );
		$response_data = current( $response );
		if ( is_object( $response_data ) && 'success' === $response_data->status ) {
			// Lets activate it for this domain if it's not.
			if ( $response_data->status_code && 's203' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
			}
			return true;
		} else if ( is_object( $response_data ) && 'error' === $response_data->status ) {
			// Lets activate it for this domain if possible.
			if ( $response_data->status_code && 'e204' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
				$response = json_decode( $response );
				end( $response );
				$response_data = current( $response );
				if ( is_object( $response_data ) && 'success' === $response_data->status ) {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	return $access;
}
add_filter( 'kadence_cloud_rest_request_access', 'custom_check_cloud_access', 10, 3 );

Restricting access to specific pattern library collections

If you wish to restrict a certain access key to only access a specific collection of schema libraries, you can do so with the following code:

/**
 * Set access to a specific pattern hub library collection.
 /** * Set access to a specific pattern hub library collection.
 /* @param array $args the query args for retrieving items. * @param string $key the access key.
 * @param string $key the access key.
 * @param array $request_extras the extra args for the request. * @return array with updated query args.
 * @return array with updated query args.
 */
function custom_kadence_cloud_query_args( $args, $key, $request_extras ) {
if ( ! isset( $args['tax_query'] ) ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'kadence-cloud-collections',
'field' => 'slug',
'terms' => array( 'COLLECTION_SLUG')
),
);
}
return $args.
}
add_filter( 'kadence_cloud_template_query_args', 'custom_kadence_cloud_query_args', 10, 3 );

Selling access keys for multiple collections

If you have multiple schema collections to sell, you can do so by setting a different license prefix for each collection:

/**
 * Validates license with WooCommerce Software License.
 *
 * @param Boolean         $access true or false based on access.
 * @param String          $key the access key.
 * @param WP_REST_Request $request full details about the request.
 * @return Boolean based on if access should be granted.
 */
function custom_check_cloud_access( $access, $key, $request ) {
	// If true the key matches with settings in Kadence Pattern Hub. Let that pass for testing purposes.
	if ( $access ) {
		return $access;
	}
	// Make sure WooCommerce Software License exists.
	global $WOO_SL_API;
	if ( $WOO_SL_API ) {
		if ( substr( $key, 0, strlen( 'col_one' ) ) === 'col_one' ) {
			$product_id = 'PRODUCT_UNIQUE_ID';
		} else {
			$product_id = 'PRODUCT_UNIQUE_ID_TWO';
		}
		$site = preg_replace('(^https?://)', '', $request->get_param( 'site' ) );
		$args =   array(
			'licence_key'       => $key,
			'domain'            => $site,
			'woo_sl_action'     => 'status-check',
			'product_unique_id' => $product_id,
		);
		$response = $WOO_SL_API->API_call( $args );
		$response = json_decode( $response );
		end( $response );
		$response_data = current( $response );
		if ( is_object( $response_data ) && 'success' === $response_data->status ) {
			// Lets activate it for this domain if it's not.
			if ( $response_data->status_code && 's203' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
			}
			return true;
		} else if ( is_object( $response_data ) && 'error' === $response_data->status ) {
			// Lets activate it for this domain if possible.
			if ( $response_data->status_code && 'e204' === $response_data->status_code ) {
				$args['woo_sl_action'] = 'activate';
				$response = $WOO_SL_API->API_call( $args );
				$response = json_decode( $response );
				end( $response );
				$response_data = current( $response );
				if ( is_object( $response_data ) && 'success' === $response_data->status ) {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	return $access;
}
add_filter( 'kadence_cloud_rest_request_access', 'custom_check_cloud_access', 10, 3 );

License Manager for WooCommerce Filter Settings

If you're using the License Manager for WooCommerce plug-in, the following PHP The code will help you verify the validity of the license:

/**
 * Validates license with license manager for woocommerce.
 /** * Validates license with license manager for woocommerce.
 * @param Boolean $access true or false based on access.
 * @param String $key the access key.
 * @param WP_REST_Request $request full details about the request. * @return Boolean based on WP_REST_Request.
 * @return Boolean based on if access should be granted.
 */ @return Boolean based on if access should be granted.
function custom_check_cloud_access( $access, $key, $request ) {
// If true the key matches with settings in Kadence Cloud.
If true the key matches with settings in Kadence Cloud. if ( $access ) {
if ( $access ) { return $access; // If true the key matches with settings in Kadence Cloud.
}
// Make sure license manager for woocommerce exists.
if ( class_exists( 'LicenseManagerForWooCommerce\Repositories\Resources\License' ) ) {
$license = \LicenseManagerForWooCommerce\Repositories\Resources\License::instance()->findBy(
array( 'hash' => apply_filters( 'lmfwc_hash', $key ) )
);
if ( ! $license ) {
// No license was found.
return false; } else { // No license was found.
} else {
// Check if expired.
$expiresAt = $license->getExpiresAt(); $dateExpiresAt = new DateTime($expires)
$dateExpiresAt = new DateTime($expiresAt); $dateNow
$dateNow = new DateTime('now', new DateTimeZone('UTC'));
if ( $dateNow getTimesActivated() ) update(
$license->getId(),
array(
'times_activated' => $timesActivatedNew
)
);
}
// We have success lets return true.
We have success lets return true.
}
}
return $access; }
}
add_filter( 'kadence_cloud_rest_request_access', 'custom_check_cloud_access', 10, 3 );

summarize

combining WooCommerce software license plug-in or License Manager for WooCommerce plug-in.Kadence Pattern Hub provides powerful access key management features. These plugins help you easily manage access keys, set up precise permission controls, and support the sale of multiple collections, greatly facilitating content sales and management.


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
Customer Service
Customer Service
Tel: 020-2206-9892
QQ咨詢:1025174874
(iii) E-mail: info@361sale.com
Working hours: Monday to Friday, 9:30-18:30, holidays off
? Reprint statement
This article was written by: thieves will be rats and mice courage
THE END
If you like it, support it.
kudos464 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments