gform_freshbooks_args_pre_create

Description

This filter can be used to modify the invoice or estimate object before it is sent to Freshbooks.

Usage

The filter which would run for all Freshbooks feeds can be used like so:

add_filter( 'gform_freshbooks_args_pre_create', 'your_function_name', 10, 4 );

Parameters

  • $args object

    The Freshbooks invoice or estimate object containing the client details, line items, etc.

$args->clientId          = '';
$args->number            = '';
$args->amount            = '';
$args->status            = '';
$args->date              = '';
$args->poNumber          = '';
$args->discount          = '';
$args->notes             = '';
$args->terms             = '';
$args->organization      = '';
$args->firstName         = '';
$args->lastName          = '';
$args->pStreet1          = '';
$args->pStreet2          = '';
$args->pCity             = '';
$args->pState            = '';
$args->pCountry          = '';
$args->pCode             = '';
$args->lines             = array(
array(
'name'        => '',
'description' => '',
'unitCost'    => '',
'quantity'    => '',
'amount'      => '',
),
);
  • $form Form Object

    The Form which is currently being processed.

  • $entry Entry Object

    The Entry which is currently being processed.

  • $feed Feed Object

    The Feed which is currently being processed. Available from v2.2.3.

  • Examples

    1. Add tax

    The following example shows how you can add tax to the line items.

    add_filter( 'gform_freshbooks_args_pre_create', function ( $args, $form, $entry ) {
    $lines = $args->lines;
    foreach ( $lines as &$line ) {
    $line['tax1Name'] = 'VAT';
    $line['tax1Percent'] = 20;
    }
    $args->lines = $lines;
    
    return $args;
    }, 10, 3 );
    

    2. Set the line items

    The following example shows how you can set the invoice line items, including how a value can be retrieved from a form field.

    add_filter( 'gform_freshbooks_args_pre_create', function ( $args, $form, $entry ) {
    $lines = array();
    
    $name        = 'The name';
    $description = 'The description';
    $unit_cost   = 10.50;
    $quantity    = rgar( $entry, '5' ); // get the value from field 5
    $amount      = $unit_cost * $quantity;
    
    $lines[] = array(
    'name'        => $name,
    'description' => $description,
    'unitCost'    => $unit_cost,
    'quantity'    => $quantity,
    'amount'      => $amount,
    );
    
    $args->lines = $lines;
    
    return $args;
    }, 10, 3 );
    

    Placement

    Your code snippet should be placed in the functions.php file of your active theme.

    Source Code

    This filter is located in GFFreshBooks::export_feed() in class-gf-freshbooks.php.