Home / Admin / Sending Numerical Values Through Webhooks
Duplicate Snippet

Embed Snippet on Your Site

Sending Numerical Values Through Webhooks

This snippet allows you to send numbers through Webhooks as opposed to the default behaviour that only allows sending values as strings

<10
Code Preview
php
<?php
/**
 * Send the numerical values through webhooks.
 *
 * @link https://wpforms.com/developers/how-to-send-the-numerical-values-through-webhooks/
 */
  
function wpf_dev_webhooks_numeric_value( $filled_params, $params, $process ) {
  
    // Request Body params which values should be numeric.
    // List each variable that you want as a number and not a string here separated by a comma and listed in single quotes
    $numeric_values = [ 'experience', 'form_id' ];
  
    foreach ( $filled_params as $key => $param ) {
        if ( is_numeric( $param ) && in_array( $key, $numeric_values, true ) ) {
            $filled_params[ $key ] = (int) $param;
        }
    }
  
    return $filled_params;
  
    }
  
add_filter( 'wpforms_webhooks_process_fill_http_body_params_value', 'wpf_dev_webhooks_numeric_value', 10, 3);

Comments

Add a Comment