woo_sl/generate_license_key/predefined_keys

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

Type
Action

Arguments
(integer) $product_id
(string) $license_group_title

Description
Trigger when key extracted successfully from predefined keys list.

Example of usage

The following code send a message to admin when the number of keys is under 10

    add_action('woo_sl/generate_license_key/predefined_keys', 'custom_do_on_predefined_key_use');
    function custom_do_on_predefined_key_use( $product_id, $license_group_title )
        {
            
            $_sl_groups =   WOO_SL_functions::get_product_licensing_groups( $product_id );   
                                                                                     
            foreach($_sl_groups as  $key     => $_sl_group)
                {
                    if($_sl_group['group_title']    !=  $license_group_title )
                        continue;
                    
                    if(count($key_list) <   10)    
                        {
                            $product_post   =   get_post($product_id);
                            
                            //send a notice to admin
                            $to             =   'admin@mywebsite.com';
                            $subject        =   'Predefined List is getting low on keys';
                            $body           =   'The product ' .$product_post->post_title .' ( ID ' . $product_id . ' ) contain only ' . count($key_list) . ' keys';
                            $headers        =   array('Content-Type: text/html; charset=UTF-8');
                             
                            wp_mail( $to, $subject, $body, $headers );   
                            
                        }
                        
                    break;
                }   
        }

By woocommerce-sl,posted on September 22, 2018