Set Tax Amount Dynamically

Code

Filename: gpecf-set-tax-amount-dynamically.php

<?php
/**
 * Gravity Perks // GP eCommerce Fields // Set Tax Amount Dynamically
 * https://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
 */
// Update '123' to the Form ID
add_filter( 'gform_pre_render_123', 'gpecf_dynamic_tax_amount' );
add_filter( 'gform_pre_validation_123', 'gpecf_dynamic_tax_amount' );
add_filter( 'gform_pre_submission_filter_123', 'gpecf_dynamic_tax_amount' );
add_filter( 'gform_admin_pre_render_123', 'gpecf_dynamic_tax_amount' );
function gpecf_dynamic_tax_amount( $form ) {

	if ( $form['fields'][0]->is_form_editor() ) {
		return $form;
	}

	foreach ( $form['fields'] as &$field ) {
		// Update '4' to the Tax field ID
		if ( $field->id == 4 ) {
			$field->taxAmount = 25; // Update '25' to the tax percentage amount.
		}
	}

	return $form;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.