Add custom parameters on WC Messaging template’s

The WC Messaging plugin integrates WhatsApp Cloud Business API with WooCommerce. It sends free automated WhatsApp notifications for WooCommerce orders and provides custom trigger buttons for easily sending custom pre-defined message templates to customers.

Custom templates’ messages are able to be sent via WC Messaging. The unique features of WC Messaging are template messages with customisable parameters. To create a custom parameter, you need to include a filter hook in your code. The code demonstrates how to include customised parameters when triggering template messages, as follows:

add_filter('woom_additional_template_params', 'function_name', 10, 2);
function function_name($parameters, $order)
{

    $custom_params = array(
        "param1" => 'value1',
        "param2" => 'value2'
    );
    $parameters = array_merge($parameters, $custom_params);
    return $parameters;
}

The code mentioned above demonstrates how to provide customised parameters when selecting a template message on the WC Messaging template setting page. Once you’ve specified the parameters you require, you can select the template messages and matching parameters as needed.

Let’s go through an example:

add_filter('woom_additional_template_params', 'function_name', 10, 2);
function function_name($parameters, $order)
{

    $custom_params = array(
        "booking_id" => 123,
        "booking_name" => 'developer'
    );
    $parameters = array_merge($parameters, $custom_params);
    return $parameters;
}

After adding the filter hook ‘woom_additional_template_params’ to my functions and calling the function ‘function_name’, I received the output shown below.

The corresponding parameters appeared to be generated when I added booking_id and booking_name. 

Was this documentation helpful?
YesNo

Leave a Reply

Your email address will not be published. Required fields are marked *