Skip to content

Commit 0b7b0fb

Browse files
authored
gw-gravity-forms-filter-out-zero-dollar-products.php: Fixed issue where zero-dollar products that had none-zero-dollar options were removed.
1 parent 4ee1e6c commit 0b7b0fb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

gravity-forms/gw-gravity-forms-filter-out-zero-dollar-products.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99
* Gravity Forms Drop Down Products which resulted in the placeholder choice being added to the
1010
* order as a zero-cost line item. We are not aware of a current need for this snippet.
1111
*/
12-
add_filter( 'gform_product_info', 'gw_remove_empty_products', 10, 3 );
13-
function gw_remove_empty_products( $product_info, $form, $lead ) {
12+
add_filter( 'gform_product_info', function ( $product_info, $form, $lead ) {
1413

1514
$products = array();
1615

1716
foreach ( $product_info['products'] as $field_id => $product ) {
1817
if ( GFCommon::to_number( $product['price'] ) != 0 ) {
1918
$products[ $field_id ] = $product;
19+
} else if ( isset( $product['options'] ) && is_array( $product['options'] ) ) {
20+
foreach ( $product['options'] as $option ) {
21+
if ( GFCommon::to_number( $option['price'] ) !== 0 ) {
22+
$products[ $field_id ] = $product;
23+
break;
24+
}
25+
}
2026
}
2127
}
2228

2329
$product_info['products'] = $products;
2430

2531
return $product_info;
26-
}
32+
}, 10, 3 );

0 commit comments

Comments
 (0)