Last active
April 10, 2022 21:15
-
-
Save spivurno/66e0d36495b7c1ed9444d6e77ecf168e to your computer and use it in GitHub Desktop.
Gravity Perks // GP Copy Cat // Copy Credit Card Name to Name Field
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
<script> | |
/** | |
* Gravity Perks // GP Copy Cat // Copy Credit Card Name to Name Field | |
* http://gravitywiz.com/ | |
*/ | |
gform.addFilter( 'gppc_copied_value', function( value, $targetElem, field ) { | |
if( field.source.split( '.' ).pop() != 5 ) { | |
return value; | |
} | |
$source = jQuery( '#input_' + field.sourceFormId + '_' + field.source.split( '.' ).join( '_' ) ); | |
if( $source.parents( '.ginput_container_creditcard, .ginput_container_custom_card_fields' ).length <= 0 ) { | |
return value; | |
} | |
// Stripe removes the "name" attribute so that the input's value is not submitted; GPCC does not account for this | |
// so let's get the value from our source input. | |
value = $source.val(); | |
var $span = $targetElem.parents( 'span' ); | |
if( $span.hasClass( 'name_first' ) ) { | |
value = value.split( ' ' ).shift(); | |
} else if( $span.hasClass( 'name_last' ) ) { | |
values = value.split( ' ' ); | |
values.shift(); | |
value = values.join( ' ' ); | |
} | |
return value; | |
} ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replacing "ginput_container_creditcard" with "ginput_container_custom_card_fields" makes this snippet compatible with the PayPal Checkout PayPal Field. The Custom CSS Class for the PayPal Field will be formatted like "copy-4.5-to-8.3 copy-4.5-to-8.6"