Copy Product Value Without the Price

By default, choice-based Product fields will copy a raw value that includes both the selected value and the price of the selection option(s). Use this snippet to copy only the value and exclude the price.

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.
  3. Update the target field ID within the snippet.

Code

Filename: gpcc-copy-product-value.js

/**
* Gravity Perks // Copy Cat // Copy Product Value Without the Price
* https://gravitywiz.com/documentation/gravity-forms-copy-cat/
*
* Instruction Video: https://www.loom.com/share/7abbf9faca9d46769c004a7f7a62931a
*
* By default, choice-based Product fields will copy a raw value that includes
* both the selected value and the price of the selection option(s).
* Use this snippet to copy only the value and exclude the price.
*
* 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.
* 3. Update the target field ID within the snippet.
*/
gform.addFilter( 'gppc_copied_value', function( value, $elem, data ) {
	// Update "1" to the ID of the field being copied to.
	if( data.target == 1 && value ) {
		value = value.split( '|' )[0];
	}
	return value;
} );

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.