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

ParameterTypeDescription
$argsobjectThe Freshbooks invoice or estimate object containing the client details, line items, etc.
$formForm ObjectThe Form which is currently being processed.
$entryEntry ObjectThe Entry which is currently being processed.
$feedFeed ObjectThe Feed which is currently being processed. Available from v2.2.3.
$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'      => '',
    ),
);

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

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

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