Adding additional fields

— Based on estimates 1 person

Video "Adding additional fields"

There are several ways to add additional fields in the plugin. Consider an example of adding custom fields in WordPress. Other CMS have similar functionality (look for the name of filters or hooks in the plugin documentation for the desired CMS). This instruction is intended for webmasters.

Universal way

This method is good because it is built on the basis of the SDK and is not tied to the CMS and is used for any submission. For example, let's consider a task where when submitting any form or order, you must always add HTTP_REFERER, SITE_DOMAIN and Google Client ID without GA. The disadvantage of this method is that it works until all fields are received, i.e. in fact, you will not know which fields you are passing. If this is WordPress, then the first and stable entry point of any file is functions.php. To solve this problem, add the following code to the functions.php file:

try {
	$flamix_extra_fields = [
                'SITE_DOMAIN' => 'mysite.com',

	$cookie_ids = \Flamix\Conversions\Conversion::getFromCookie();
	if(!empty($cookie_ids) && isset($cookie_ids['_ga']))
		$flamix_extra_fields['google_client_id'] = preg_replace('/GA[0-9].[0-9]./', '', $cookie_ids['_ga']);

    unset($cookie_ids, $flamix_extra_fields);
} catch (\Exception $e) {

WordPress Filters

If you need to change order fields or goods using previously created fields (for example, order number, customer name, etc.), you must use filters. We place filters in the functions.php file. The available filters are:

  • flamix_bitrix24_integrations_fields_filter $fields
  • flamix_bitrix24_integrations_product_filter $products, $order_id
  • flamix_bitrix24_integrations_filter $data

Pay attention! Filters are universal for all WordPress plugins! This means that if you change the fields using flamix_bitrix24_integrations_fields_filter, then the filter will be applied both for the WooCommerce module and for Contact Form 7 or Ninja Form. This restriction obliges you not to be 100% sure that some of the incoming parameters will definitely be. For example, ORDER_ID will only be in WooCommerce. An example of implementing the task of adding a title for a Lead with the necessary information:

function flamix_bitrix24_integrations_fields_example_callback($fields) {
    if(isset($fields['ORDER_ID']) && $fields['ORDER_ID'] > 0)
        $fields['MY_BITRIX24_LEAD_TITLE'] = 'Order #' . ($fields['ORDER_ID'] ?? 0) . ' from wp.app.flamix.solutions at ' . ($fields['DATE'] ?? date('Y-m-d H:m:s'));
        $fields['MY_BITRIX24_LEAD_TITLE'] = 'Request from wp.app.flamix.solutions at ' . ($fields['DATE'] ?? date('Y-m-d H:m:s'));

        return $fields;
add_filter( 'flamix_bitrix24_integrations_fields_filter', 'flamix_bitrix24_integrations_fields_example_callback', 10, 3 );