Display Price Labels (JS)

This snippet requires the PHP counterpart gpcp-product-pricing-labels.php

Code

Filename: gpcp-product-pricing-labels.js

/**
 * Gravity Perks // GP Conditional Pricing // Display Price Labels (JS)
 * https://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 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.