Woocommerce kit and variations

I’m a little confused. Assuming I want to distribute three license versions like license 1 with 1 month, a license with 12 months and an unlimited license, this would be possible because a variable product has a unique ID, right?

So i would install different activation kits with that unique id, so every license version got its own license kit. Does that work?

Or what is the exact problem with that?

Yes, and you create a different “activation” subfolder in your WordPress website for each variation.

Yes. Several WooCommerce Integration Kits can be installed on the same woocommerce website. However, in your case, you would have to modify the PHP source code to change the expiration date for the activation key, based on which product ID was purchased.

BlockquoteHowever, in your case, you would have to modify the PHP source code to change the expiration date for the activation key, based on which product ID was purchased.

You mean customizing the maincontroller.php?

Yes, in this function:

The controller could be customized so that depending on the product_id available in the order, a different expiration setting is configured.

Hi, i followed the instructions. Now, i have variable products according to different licence models.
Nevertheless, i get the following message. At the moment, there is just one product created for testing
May you please give me advise what this means, please?

image

When i have the product created as a simple product it works fine. May i let the "wpcheckproductid = " field empty? The product id is 1860 (for e.g.) and the id of the variable is #1950. Can i add #1950?

The problem is due to the incorrect product ID in the order.
If you want to check for variations, you should modify the PHP code in the controller:

// Check if the order contains the product that is allowed (the product id is defined in config.ini)

$allowed_prod_id = $f3->get(‘wpcheckproductid’);

if (!empty($allowed_prod_id))
{

  $is_valid = false;
  					
  	// Scan all ordered items in the order
  	$order_items = $order_data->line_items;
  						
  foreach ( $order_items as $order_item )
  {
  		if ($order_item->product_id == $allowed_prod_id)

Then, in that loop, you must also check for possible allowed variations:

{
if ($order_item->variation_id == 1950)

1 Like

Sorry for jumping the discussion, but I have a similar issue.
Say the variation_ID is 1950 corresponding to a licence length of 30 days which is an attribute of that variation product. How can I extract that attribute with that variation_ID?
A series of attributes would be something like 30 days|60 days|90 days|365 days|999999 days|

$allowed_prod_id = $f3->get('wpcheckproductid');
					
					if (!empty($allowed_prod_id))
					{
					
						$is_valid = false;
						
						// Scan all ordered items in the order
						$order_items = $order_data->line_items;
							
							foreach ( $order_items as $order_item )
							{
								if ($order_item->product_id == $allowed_prod_id)
								{
									$is_valid = true;
									break;
								}
								//
								if($order_item->variation_id == 1950) {
									$is_valid = true;
									break;
								}
							}
						if (!$is_valid)
						{
							throw new Exception("The order associated to your account does not contain the authorized product. Cannot continue.");

						}
					}

That way?

Yes, but remove the first break otherwise the second “if” will be ignored.

It would be better to change the maincontroller.php’s code depending on the variation ID to create a key with a different expiration date. As you can see gere, WooCommerce doesn’t give us a lot of information about purchased products (product id, variation id and no custom entries).
http://woocommerce.github.io/woocommerce-rest-api-docs/#order-properties

It works with both variants

Thanks for your reply. I’ve modified the MainController.php, so now it is able to allow multiple variations of ONE product with only ONE kit installation. It also can expire the licences based on purchased licence lengths. I marked the location where I made changes to the php file - search for the “xxx” text. It works for me, and you may want to implement it some ways to the standard kit to benefit everyone in this community If you think it is useful. See the full code below:
[edit removed]

Thanks. Removed the entire full code though. Customers who want it can request it by Private Mail.
Sure, we’ll continue to extend the kit with additional options, however we must also keep things simple to install and configure.

1 Like

I have a question about having multiple installations of the woocommerce file. Do I need to create a new user with separate API keys for each folder?

No, one user with the same API keys is enough.

Great! Thank you for the quick response.

I want this code please :slight_smile: :slight_smile:

Hi support, can you please download the file and share it somewhere in your website so others can download it? Some people pm me asking for the file, but I can’t promise to reply them all timely. On the other hand, sharing the code via pm makes its format funny.
The file can be downloaded at the below link:
https://ufile.io/x9zk2
The link is valid only within 30 days
You may want to delete the link if needed.
Another feature that I forgot to mention: the expiry date of an activation is calculated based on the ‘completed order’ date, hence If users re-activate the software, the expired date would stay the same.

amazing ! this is exactly what I ask for in the Woo Commerce Kit New function request

but there is one more thing to add to this logic:
if the customer renew his license (purchase) NOT in the end of his previous let say a week before the “expire date” the new license should start in the next day after the previous license, otherwise he will lose a week to his new license.