Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save claygriffiths/55ae6f5e3be5cf1062eeb3d164a9937d to your computer and use it in GitHub Desktop.
Save claygriffiths/55ae6f5e3be5cf1062eeb3d164a9937d to your computer and use it in GitHub Desktop.
GP eCommerce Fields + Gravity Forms Product Add-ons for WooCommerce: Exclude Tax Fields
<?php
/**
* Note: See https://gravitywiz.com/documentation/how-do-i-install-a-snippet/ for details on how to install snippets.
*
* Normally, GP eCommerce Fields Tax fields will be treated as Gravity Forms products when passed to WC Product Add-ons.
* If WooCommerce is configured to handle taxes, passing the tax fields will result in double-taxation.
*
* This snippet prevents the tax fields/product from being added to WooCommerce cart.
*
* Use case: Display the tax on the product page to help show the customer a tax
* estimate prior to getting to the cart.
*/
add_filter( 'gform_product_info', 'gwiz_exclude_tax_fields_from_wc_product_addons' );
function gwiz_exclude_tax_fields_from_wc_product_addons( $product_info ) {
$products = $product_info['products'];
if ( ! empty( $products ) && is_array( $products ) ) {
$product_info['products'] = array_filter( $products, function ( $product ) {
return ! rgar( $product, 'isTax' );
} );
}
return $product_info;
}
@shaunonz
Copy link

Lifesaver - thank you!!!

@claygriffiths
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment