Show the original price crossed out next to the adjusted price

Instructions

  1. Install our free Custom Javascript for Gravity Forms plugin.
    Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
    
    1. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.

Code

Filename: gpcp-show-original-price.js

/**
 * Gravity Perks // GP Conditional Pricing // Show the original price crossed out next to the adjusted price
 * https://gravitywiz.com/documentation/gravity-forms-conditional-pricing/
 *
 * Instructions:
 *     1. Install our free Custom Javascript for Gravity Forms plugin.
 *        Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 *     2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 */
 gform.addAction( 'gpcp_after_update_pricing', function( productId, GWConditionalPricing ) {

	var basePrice = GWConditionalPricing.getBasePrice( productId );
	if ( ! basePrice ) {
		return;
	}

	var $input = $( '#input_{0}_{1}'.gformFormat( GWConditionalPricing._formId, productId ) );
	if ( ! $input.length ) {
		return;
	}

	var $basePrice = $( '#base_price_{0}_{1}'.gformFormat( GWConditionalPricing._formId, productId ) );

	// Remove base price if there is no discounted price.
	if ( $input.text() === basePrice ) {
		$basePrice.remove();
	}
	// Otherwise, add base price if it has not been added.
	else if ( ! $basePrice.length ) {
		$basePrice = '<span id="base_price_{0}_{1}" style="text-decoration:line-through;margin-right:0.3rem">{2}</span>'.gformFormat( GWConditionalPricing._formId, productId, basePrice );
		$input.before( $basePrice );
	}

} );

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.