Last active
April 28, 2023 08:34
-
-
Save mattiasghodsian/c34a8f03222c683745725ef1c61dc475 to your computer and use it in GitHub Desktop.
[WordPress] Gravity Forms display price
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
/** | |
* Title: Gravity Forms display price | |
* Description: Display (has) price on Drop Down and Radio Button Product Fields | |
* Source: https://www.gravityhelp.com/documentation/article/gform_field_choice_markup_pre_render/#2-include-price-for-product-fields | |
* Author: Mattias Ghodsian | |
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
*/ | |
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field, $value ) { | |
if ( $field->type == 'product' ) { | |
if ( !empty($choice['price']) ) { | |
$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