Generate a different number of keys than default, for a licensed product along with WP Software License

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPrint this page

By woocommerce-sl, posted on August 2, 2017

By default, whenever a client purchases a licensed product, a single key is generated and saved within the account. This can be changed through the filter woo_sl/generate_licence_keys_count. Multiple keys can be generated in a row, or none.

The example bellow change the default single key generator to all allowed for current licence group:

add_action('woo_sl/generate_licence_keys_count', 'woo_sl_generate_licence_keys_count', 10,  4);
    function woo_sl_generate_licence_keys_count($generate_keys_count, $order_id, $order_item_id, $license_group_id)
        {
            global $WOO_SL_API;
            
            $_woo_sl    =   $WOO_SL_API->functions->get_order_item_meta($order_item_id,  '_woo_sl',  TRUE);
            
            $group_max_allowed_keys     =   $_woo_sl['max_keys'][$license_group_id];
            
            return $group_max_allowed_keys;   
        }

If the order contain multiple quantity of an item, the user will be able to generate a maximum_group_licence_keys multiplied with quantity. So accordingly the code become something like this:

add_action('woo_sl/generate_licence_keys_count', 'woo_sl_generate_licence_keys_count', 10,  4);
    function woo_sl_generate_licence_keys_count($generate_keys_count, $order_id, $order_item_id, $license_group_id)
        {
            global $WOO_SL_API;
            
            $_woo_sl    =   $WOO_SL_API->functions->get_order_item_meta($order_item_id,  '_woo_sl',  TRUE);
            
            $group_max_allowed_keys     =   $_woo_sl['max_keys'][$license_group_id];

            $order_data         = new WC_Order($order_id);
            $order_products     = $order_data->get_items();

            $order_item_data    = $order_products[$order_item_id];
            $quantity           = $order_item_data['qty'];
            
            return ($quantity * $group_max_allowed_keys);
        }

Category: ,
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments