Skip to content

Commit

Permalink
gw-gravity-forms-filter-out-zero-dollar-products.php: Fixed issue w…
Browse files Browse the repository at this point in the history
…here zero-dollar products that had none-zero-dollar options were removed.
  • Loading branch information
spivurno authored Jan 10, 2025
1 parent 4ee1e6c commit 0b7b0fb
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
* Gravity Forms Drop Down Products which resulted in the placeholder choice being added to the
* order as a zero-cost line item. We are not aware of a current need for this snippet.
*/
add_filter( 'gform_product_info', 'gw_remove_empty_products', 10, 3 );
function gw_remove_empty_products( $product_info, $form, $lead ) {
add_filter( 'gform_product_info', function ( $product_info, $form, $lead ) {

$products = array();

foreach ( $product_info['products'] as $field_id => $product ) {
if ( GFCommon::to_number( $product['price'] ) != 0 ) {
$products[ $field_id ] = $product;
} else if ( isset( $product['options'] ) && is_array( $product['options'] ) ) {

Check warning on line 19 in gravity-forms/gw-gravity-forms-filter-out-zero-dollar-products.php

View workflow job for this annotation

GitHub Actions / PHPCS

Usage of ELSE IF is discouraged; use ELSEIF instead
foreach ( $product['options'] as $option ) {
if ( GFCommon::to_number( $option['price'] ) !== 0 ) {
$products[ $field_id ] = $product;
break;
}
}
}
}

$product_info['products'] = $products;

return $product_info;
}
}, 10, 3 );

0 comments on commit 0b7b0fb

Please sign in to comment.