WOOSL/API_call/response

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

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']) ? $args['product_unique_id'] : '';
                $licence_key        = isset($args['licence_key'])       ? $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;
            }

By woocommerce-sl,posted on August 2, 2017