Created
June 27, 2020 16:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lifesaver - thank you!!!