Using Gravity Forms ‘gform_zapier_products’ PHP filter

The gform_zapier_products Gravity Forms PHP filter allows you to modify the products array before it is sent to Zapier.

Usage

add_filter('gform_zapier_products', 'your_function_name', 10, 3);

Parameters

  • $products (array): An array of product information.
  • $form (Form Object): The form object.
  • $entry (Entry Object): The current entry.

More information

See Gravity Forms Docs: gform_zapier_products

Examples

Add a test product to the products array

This example demonstrates how to add a test product to the products array before sending it to Zapier.

add_filter('gform_zapier_products', 'modify_products', 10, 3);

function modify_products($products, $form, $entry) {
    $products[] = array(
        'product_id' => 'TEST01',
        'product_name' => 'Test Product',
        'product_quantity' => 2,
        'product_price' => 5,
        'product_price_with_options' => 5,
        'product_subtotal' => 10,
        'product_options' => 'Blue'
    );
    return $products;
}

Change product quantity

This example demonstrates how to change the quantity of a specific product before sending it to Zapier.

add_filter('gform_zapier_products', 'change_product_quantity', 10, 3);

function change_product_quantity($products, $form, $entry) {
    foreach ($products as &$product) {
        if ($product['product_id'] == '123') {
            $product['product_quantity'] = 10;
        }
    }
    return $products;
}

Remove a product

This example demonstrates how to remove a specific product from the products array before sending it to Zapier.

add_filter('gform_zapier_products', 'remove_product', 10, 3);

function remove_product($products, $form, $entry) {
    foreach ($products as $key => $product) {
        if ($product['product_id'] == '456') {
            unset($products[$key]);
        }
    }
    return $products;
}

Apply a discount

This example demonstrates how to apply a discount to a specific product before sending it to Zapier.

add_filter('gform_zapier_products', 'apply_discount', 10, 3);

function apply_discount($products, $form, $entry) {
    foreach ($products as &$product) {
        if ($product['product_id'] == '789') {
            $product['product_price'] *= 0.9; // Apply a 10% discount
            $product['product_subtotal'] = $product['product_price'] * $product['product_quantity'];
        }
    }
    return $products;
}

Add custom product options

This example demonstrates how to add custom product options to a specific product before sending it to Zapier.

add_filter('gform_zapier_products', 'add_custom_options', 10, 3);

function add_custom_options($products, $form, $entry) {
    foreach ($products as &$product) {
        if ($product['product_id'] == '321') {
            $product['product_options'] .= ', Custom Engraving';
        }
    }
    return $products;
}