Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Last active January 11, 2024 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwanjuki/b7b3d53ebe12f64b74b2c658ec161caf to your computer and use it in GitHub Desktop.
Save dwanjuki/b7b3d53ebe12f64b74b2c658ec161caf to your computer and use it in GitHub Desktop.
Show live price after sponsored seats section at checkout
<?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