Skip to content

Instantly share code, notes, and snippets.

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 andrewlimaza/579e0a6d985c5230b21e40deb5af0448 to your computer and use it in GitHub Desktop.
Save andrewlimaza/579e0a6d985c5230b21e40deb5af0448 to your computer and use it in GitHub Desktop.
Remove Billing Fields for Offsite Payment Gateways using the Address For Free Levels Add On. Paid Memberships Pro
<?php
/**
* This code snippet will hide billing fields from certain levels when added using the "Capture Name & Address for Free Levels or for Offsite Gateway"
* Please adjust the level ID's values of the $levels_to_hide array, for which levels you want to hide billing fields from.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_hide_billing_fields_for_levels() {
$levels_to_hide = array(1,3,5); //change level ID's you want to hide billing fields from.
$level = pmpro_getLevelAtCheckout();
if ( in_array( $level, $levels_to_hide ) ) {
remove_action( 'init', 'pmproaffl_init_include_address_fields_at_checkout', 30 );
remove_action( "pmpro_checkout_boxes", "pmproaffl_pmpro_checkout_boxes_require_address" );
remove_action("pmpro_required_billing_fields", "pmproaffl_pmpro_required_billing_fields", 30);
remove_action("pmpro_paypalexpress_session_vars", "pmproaffl_pmpro_paypalexpress_session_vars");
remove_action("pmpro_before_send_to_twocheckout", "pmproaffl_pmpro_paypalexpress_session_vars", 10, 2);
remove_action( 'pmpro_checkout_before_change_membership_level', 'pmproaffl_pmpro_checkout_before_change_membership_level', 5, 2);
remove_action( 'pmpro_checkout_preheader', 'pmproaffl_init_load_session_vars', 5 );
remove_filter( 'pmpro_checkout_order_free', 'pmproaffl_pmpro_checkout_order_free' );
}
}
add_action( 'init', 'my_pmpro_hide_billing_fields_for_levels' );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Exclude billing fields from some membership levels at checkout." at Paid Memberships Pro here: https://www.paidmembershipspro.com/exclude-billing-fields-from-some-membership-levels-at-checkout/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment