Skip to content

Instantly share code, notes, and snippets.

@lorenzocaum
Created September 14, 2020 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzocaum/83909191de774d838fd86010dc6e413f to your computer and use it in GitHub Desktop.
Save lorenzocaum/83909191de774d838fd86010dc6e413f to your computer and use it in GitHub Desktop.
<script>
		//when page loaded
		jQuery( document ).ready(function() {
			//check if select payment button is on the page
			if(jQuery('input#spco-go-to-step-finalize_registration-submit').length)
			{
				//if it is wait for it to be clicked
				jQuery('input#spco-go-to-step-finalize_registration-submit').click( function () {	
					//make sure the form doesn't submit and instead change then submit ourselves
					jQuery(document).on( 'submit','form[name=gateway_form]', function(e) { 
						//get the grand total
						var ppamt = parseInt( jQuery('input[name=amount_1]').val() ) + parseInt( jQuery('input[name=tax_cart]').val() );
						//calculate paypal fee
						ppamt = ( (ppamt * .026) + .30 ).toFixed(2); 
						console.info('fee='+ppamt);
						//remove debug if present
						jQuery('input[name$=_2]').remove();
						//append as line item to paypal form
						var addendum = '<input type="hidden" value="Booking and Service Fee" name="item_name_2">'+
						               '<input type="hidden" value="'+ppamt+'" name="amount_2">'+
						               '<input type="hidden" value="1" name="quantity_2">';
						jQuery(addendum).appendTo('form[name=gateway_form]');
						return true;
					});
				});
			}
		});
	</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment