-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added gpcp-product-pricing-labels.js and gpcp-product-pricing-labels.…
…php (#18) * Added gpcp-product-pricing-labels.js and gpcp-product-pricing-labels.php Original gist: https://gist.github.com/spivurno/cc461abccceaf9aec531210cb0846476 * Added var in front of variables and replaced EOL commas with semicolons
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Gravity Perks // GP Conditional Pricing // Display Price Labels (JS) | ||
* http://gravitywiz.com/documentation/gravity-forms-conditional-pricing/ | ||
* | ||
* This snippet requires the PHP counterpart gpcp-product-pricing-labels.php | ||
*/ | ||
( function( $ ) { | ||
function update_price_labels() { | ||
$( 'label[data-gpcp-template], option[data-gpcp-template]' ).each( function() { | ||
var $priceElem = $( this ).is( 'option' ) ? $( this ) : $( this ).siblings( 'input' ); | ||
var price = gformFormatMoney( $priceElem.val().split( '|' )[1] ); | ||
var template = $( this ).attr( 'data-gpcp-template' ); | ||
$( this ).html( template.replace( '{price}', price ) ); | ||
} ); | ||
} | ||
gform.addAction( 'gpcp_after_update_pricing', update_price_labels); | ||
update_price_labels(); | ||
} )( jQuery ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Gravity Perks // GP Conditional Pricing // Display Price Labels (PHP) | ||
* http://gravitywiz.com/documentation/gravity-forms-conditional-pricing/ | ||
* | ||
* This snippet requires the JS counterpart gpcp-product-pricing-labels.js | ||
*/ | ||
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 ); |