Actions / Filters

By woocommerce-sl, posted on January 27, 2021

Type
Filter

Arguments
(array) $response
(array) $args
(class) $api_object

Description
Allows filtering the API response by adding a custom response item on top of everything else.

Observation
The cache module need to be off for the filter to trigger.

Example of usage
Return additional response with a timestamp call, on top of the other API messages.

    add_filter( 'WOOSL/API_call/early_response', 'WOOSL_API_call_early_response', 10, 3 );
    function WOOSL_API_call_early_response ( $response, $args, $object )
        {
            
            $response[] =   array ( 
                                    'status'    =>  'success',
                                    'timestamp' =>  time(),
                                    'message'   =>  'API call time'
                                        );
               
            return $response;   
        }

Read more

By woocommerce-sl, posted on February 9, 2022

Type
Filter

Arguments
(bool) $do_action
(array) $args
(class) $api_object

Description
Allows bypassing the API do action procedure. The filter should be used in conjunction with WOOSL/API_call/early_response or WOOSL/API_call/response to provide custom responses.

Observation
The cache module needs to be off for the filter to trigger.

Example of usage
Ignore the internal API status-check action.

        add_filter( 'WOOSL/API_call/do_action', 'WOOSL_API_call_do_action', 10, 3 );
        function WOOSL_API_call_do_action ( $do_action, $args, $object )
            {
                
                if ( $args['woo_sl_action'] == 'status-check' )
                    $do_action  =   FALSE;
                   
                return $do_action;   
            }

Read more

By woocommerce-sl, posted on February 22, 2022

Type
Filter

Arguments
(array) $response
(array) $args

Description
Add additional data to the API current response block.

Observation
The cache module needs to be off for the filter to trigger. Or ensure the custom code is placed within the /wp-content/mu-plugins/woosl-custom.php file

Example of usage
Add the customer full name to the response.

    add_filter( 'WOOSL/API_call/response_block', '__woosl_api_additional_response', 10, 2 );
    function __woosl_api_additional_response ( $response, $args )
        {
            
            $licence_key_data = WOO_SL_functions::get_licence_key_data_by_licence_key( $args['licence_key'] );
            if ( ! is_object ( $licence_key_data ) )
                return $response;
                
            $response['customer_name']  =   get_post_meta( $licence_key_data->order_id, '_billing_first_name', TRUE ) . " " . get_post_meta( $licence_key_data->order_id, '_billing_last_name', TRUE );
            
            return $response;    
        }

Read more

By woocommerce-sl, posted on February 22, 2022

Type
Filter

Arguments
(array) $filtered_machine_hash
(array) $machine_hash

Description
Apply custom filtering for the customer machine hash. This can be a domain name, a unique ID etc. Use the filter to avoid the core further processing this variable value.

Observation
The cache module needs to be off for the filter to trigger. Or ensure the custom code is placed within the /wp-content/mu-plugins/woosl-custom.php file

Example of usage
Ensure all the strings are uppercase.

    add_filter( 'WOOSL/API_call/clean_machine_hash', '__woosl_api_clean_machine_hash', 10, 2 );   
    function __woosl_api_clean_machine_hash( $filtered_machine_hash, $machine_hash )
        {
            $filtered_machine_hash  =   strtoupper( $machine_hash );
            
            return $filtered_machine_hash;   
        }

Read more

By woocommerce-sl, posted on August 2, 2017

Type
Filter

Arguments
(array) $response
(array) $args
(class) $api_object

Description
Allow to filter the API response.

Observation
The cache module need to be off for the filter to trigger.

Example of usage
Return additional custom field on key activation.

        add_filter('WOOSL/API_call/response', 'woosl_api_call_response', 10, 3);
        function woosl_api_call_response( $response, $args, $api_object )
            {
                //check if the API call method is not activate
                if  ( $args['woo_sl_action']    !=  'activate' ) 
                    return $response;
                    
                //feetch the last response in the list
                reset ( $response );
                
                $response   =   current( $response );
                
                //check for specific status, if operation was sucess
                if  (   ! in_array( 's100', $response['status_code'])   ||  ! in_array( 's100', $response['status_code']) )
                    return $response;
                
                //retrieve the product id
                $product_unique_id  = isset($args['product_unique_id']) ?   preg_replace("/[^a-zA-Z0-9.\-\_ ]/", "", $args['product_unique_id'] )       : '';
                $licence_key        = isset($args['licence_key'])       ?   preg_replace("/[^a-zA-Z0-9.\-\_\: ]/", "", $args['licence_key'] )             : '';
                $product_id = $api_object->product_validation($licence_key, $product_unique_id);
                
                //add the additional field
                $additional_field   =   get_post_meta( $product_id, 'field_name', TRUE );  
                
                $response['new_field']  =   $additional_field;
                          
                return $response;
            }

The following example returns an additional field with the customer name.

    add_filter('WOOSL/API_call/response', '_woosl_api_call_response', 10, 3);
    function _woosl_api_call_response( $response, $args, $api_object )
        {
            //check if the API call method is not activate
            if  ( $args['woo_sl_action']    !=  'status-check' ) 
                return $response;
                 
            //feetch the last response in the list
            reset ( $response );
             
            $response_block   =   current( $response );
             
            //check for specific status, if operation was sucess
            if  (   ! in_array( $response_block['status_code'], array ( 's203', 's205', 's215'  ) ) )
                return $response;
            
            $WOO_SL_Functions = new WOO_SL_functions();
             
            //retrieve the product id
            $product_unique_id  = isset($args['product_unique_id']) ?   preg_replace("/[^a-zA-Z0-9.\-\_ ]/", "", $args['product_unique_id'] )       : '';
            $licence_key        = isset($args['licence_key'])       ?   preg_replace("/[^a-zA-Z0-9.\-\_\: ]/", "", $args['licence_key'] )             : '';
            $product_id = $api_object->product_validation($licence_key, $product_unique_id);
            
            $licence_key_data   =   $WOO_SL_Functions->get_licence_key_data_by_licence_key( $licence_key );
            
            $order_data =   wc_get_order( $licence_key_data->order_id );
             
            //add the additional field
            $response_block['customer_name']  =   $order_data->billing_first_name . ' ' . $order_data->billing_last_name;
            
            $response[ key ( $response ) ]  =   $response_block;
                       
            return $response;
        }

Read more

By woocommerce-sl, posted on August 2, 2017

Type
Filter

Arguments
(array) $args
(class) $api_object

Description
Allows filtering the argument data passed through the API.

Observation
The cache module needs to be off for the filter to trigger.

Example of usage
Add additional argument.

        add_filter( 'WOOSL/API_call/arguments', 'WOOSL_API_call_arguments', 10, 3 );
        function WOOSL_API_call_arguments ( $args, $object )
            {
                
                $args['client_hash'] = md5( $_SERVER['HTTP_USER_AGENT'] );
                   
                return $args;  
            }

Read more