Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JarrydLong/ad3f2fd3d1c1cc41a1c7c533a1df3d8a to your computer and use it in GitHub Desktop.
Save JarrydLong/ad3f2fd3d1c1cc41a1c7c533a1df3d8a to your computer and use it in GitHub Desktop.
Select Paid Memberships Pro Payment Plan via query parameter
<?php
/**
* Add &pmpropp_chosen_plan=<<plan_id>> in the URL to preselect the payment plan option.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_payment_plan_select_url() {
// Only load this on the checkout page.
if ( function_exists('pmpro_is_checkout') && !pmpro_is_checkout() ) {
return;
}
?>
<script>
jQuery( document ).ready(function() {
const urlParams = new URLSearchParams(window.location.search);
const payment_plan_query = urlParams.get('pmpropp_chosen_plan');
const payment_plan_level = urlParams.get('pmpro_level');
jQuery( "#pmpropp_chosen_plan_choice_L-"+payment_plan_level+"-P-"+payment_plan_query ).click();
});
</script>
<?php
}
add_action( 'wp_footer', 'my_pmpro_payment_plan_select_url' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment