Last active
January 11, 2024 15:01
-
-
Save dwanjuki/b7b3d53ebe12f64b74b2c658ec161caf to your computer and use it in GitHub Desktop.
Show live price after sponsored seats section at checkout
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
<?php | |
/* | |
* Show live price after sponsored seats section at checkout | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_live_price( $param ) { | |
$sponsor_levels = array( 7, 9, 11 ); // live price shown for these level IDs only | |
if( ! in_array( $_REQUEST['level'], $sponsor_levels ) ) { | |
return; | |
} | |
?> | |
<h4 id='pmpro_live_price'>Total: $x.xx</h4> | |
<script> | |
jQuery(document).ready(function () { | |
function pmproUpdateLivePrice() { | |
setTimeout(function(){ | |
jQuery.noConflict().ajax({ | |
url: '<?php echo( esc_url( get_rest_url() ) ); ?>pmpro/v1/checkout_levels', | |
dataType: 'json', | |
data: pmpro_getCheckoutFormDataForCheckoutLevels(), | |
success: function(data) { | |
console.log(data); | |
if ( data.hasOwnProperty('initial_payment_formatted') ) { | |
jQuery('#pmpro_live_price').html( "Total: " + data.initial_payment_formatted ); | |
} | |
} | |
}); | |
}, 500); | |
} | |
pmproUpdateLivePrice(); | |
jQuery('.pmpro_alter_price').change(function(){ | |
pmproUpdateLivePrice(); | |
}); | |
jQuery('#seats').on('input', function(){ | |
pmproUpdateLivePrice(); | |
}); | |
}); | |
</script> | |
<?php | |
return $param; | |
} | |
add_action( 'pmpro_checkout_boxes', 'my_pmpro_live_price' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment