spivurno
1/17/2014 - 11:23 PM

Gravity Forms // Override Tax with Gravity Forms PayPal Standard

Gravity Forms // Override Tax with Gravity Forms PayPal Standard

<?php
/**
 * Override Tax with Gravity Forms PayPal Standard
 */
add_filter( 'gform_paypal_query', 'update_paypal_query', 10, 3 );
function update_paypal_query( $query_string, $form, $entry ) {

    parse_str( $query_string, $query );

    $query['cmd'] = '_xclick';
    $query['tax'] = '2.22';
    $query['item_name'] = array();
    $query['amount'] = 0;

    foreach( $query as $key => $value ) {
        list( $prefix, $id ) = array_pad( explode( '_', $key ), 2, null );
        if( $id && $prefix == 'amount' ) {
            $query['amount'] += $query[$key] * $query['quantity_' . $id];
            $query['item_name'][] = $query['item_name_' . $id];
        }
    }

    $query['item_name'] = implode( ', ', $query['item_name'] );

    $query_string = http_build_query( $query, '', '&' );

    return '&' . $query_string;
}