Last active
March 5, 2020 01:55
-
-
Save spivurno/cc461abccceaf9aec531210cb0846476 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Conditional Pricing // Display Price Labels
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
<script> | |
gform.addAction( 'gpcp_after_update_pricing', function( triggerFieldId, gpcp ) { | |
( function( $ ) { | |
$( 'label[data-gpcp-template], option[data-gpcp-template]' ).each( function() { | |
var $priceElem = $( this ).is( 'option' ) ? $( this ) : $( this ).siblings( 'input' ), | |
price = gformFormatMoney( $priceElem.val().split( '|' )[1] ), | |
template = $( this ).attr( 'data-gpcp-template' ); | |
$( this ).html( template.replace( '{price}', price ) ); | |
} ); | |
} )( jQuery ); | |
} ); | |
</script> |
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 | |
/** | |
* Gravity Perks // GP Conditional Pricing // Display Price Labels | |
* http://gravitywiz.com/documentation/gravity-forms-conditional-pricing/ | |
*/ | |
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field, $value ) { | |
// Edit the template here. Use {label} to represent the original choice label and {price} where ever you would like to include the choice price. | |
$template = '{label} - {price}'; | |
// No need to edit below. | |
if ( $field->type === 'product' ) { | |
$template = str_replace( '{label}', $choice['text'], $template ); | |
$replace = sprintf( ' data-gpcp-template="%s">%s<', $template, str_replace( '{price}', GFCommon::to_money( $choice['price'] ), $template ) ); | |
$choice_markup = str_replace( ">{$choice['text']}<", $replace, $choice_markup );; | |
} | |
return $choice_markup; | |
}, 10, 4 ); |
I agree with @ntreegdesigns - The default prices are displayed, but I can't get the conditional price(s) to appear, even if I put the condition field on an earlier page. The {subtotal} merge tag updates correctly, so I know that my conditional pricing is setup correctly.
@Wordna1 Drop us a line via support and we'll be happy to dig in. 🙂
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, thanks for this code. I am attempting to show the conditional price as a label on radio selections but when I add the php, it only shows $0.00 as the label instead of the conditional price. How could I go about placing the conditional prices directly on radio labels? Thanks for your time.