Last active
May 19, 2023 21:48
-
-
Save spivurno/a52923aadd37cc0151ce33c92662ba60 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Display Price for Drop Down and Radio Button Product Fields
This file contains 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 | |
/** | |
* Gravity Wiz // Gravity Forms // Display Price for Drop Down and Radio Button Product Fields | |
* http://gravitywiz.com/ | |
* Source: https://www.gravityhelp.com/documentation/article/gform_field_choice_markup_pre_render/#2-include-price-for-product-fields | |
*/ | |
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field, $value ) { | |
if ( $field->type == 'product' ) { | |
$new_string = sprintf( '>%s - %s<', $choice['text'], GFCommon::to_money( $choice['price'] ) ); | |
return str_replace( ">{$choice['text']}<", $new_string, $choice_markup ); | |
} | |
return $choice_markup; | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-display-prices-for-choice-based-product-fields.php