Advertisement
agir

PMPCustomization

Feb 24th, 2020
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.66 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: PMPro Customizations
  4. Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/
  5. Description: Customizations for my Paid Memberships Pro Setup
  6. Version: .1
  7. Author: Paid Memberships Pro
  8. Author URI: https://www.paidmembershipspro.com
  9. */
  10.  
  11. //Now start placing your customization code below this line
  12.  
  13.  
  14.  
  15. /**
  16.  * This will show the renewal date link within the number of days or less than the members expiration that you set in the code gist below.
  17.  * Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
  18.  */
  19. function show_renewal_link_after_X_days( $r, $level ) {
  20.  
  21.     if ( empty( $level->enddate ) ) {
  22.         return false;
  23.     }
  24.  
  25.     $days = 60; // Change this to value.
  26.  
  27.     // Are we within the days until expiration?
  28.     $now = current_time( 'timestamp' );
  29.  
  30.     if ( $now + ( $days * 3600 * 24 ) >= $level->enddate ) {
  31.         $r = true;
  32.     } else {
  33.         $r = false;
  34.     }
  35.  
  36.     return $r;
  37. }
  38.  
  39. add_filter( 'pmpro_is_level_expiring_soon', 'show_renewal_link_after_X_days', 10, 2 );
  40.  
  41. /**
  42.  * Show next payment date under 'Expiration' field in PMPro account page.
  43.  * Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
  44.  * Works for PayPal Express and Stripe payment gateways.
  45.  * www.paidmembershipspro.com
  46.  */
  47. // Change the expiration text to show the next payment date instead of the expiration date
  48. // This hook is setup in the wp_renewal_dates_setup function below
  49. function my_pmpro_expiration_text($expiration_text) {
  50.     global $current_user;
  51.     $next_payment = pmpro_next_payment();
  52.        
  53.     if( $next_payment ){
  54.         $expiration_text = date_i18n( get_option( 'date_format' ), $next_payment );
  55.     }
  56.    
  57.     return $expiration_text;
  58. }
  59.  
  60. // Change "expiration date" to "renewal date"
  61. // This hook is setup in the wp_renewal_dates_setup function below
  62. function change_expiration_date_to_renewal_date($translated_text, $original_text, $domain) {
  63.     if($domain === 'paid-memberships-pro' && $original_text === 'Expiration')
  64.         $translated_text = 'Renewal Date';
  65.    
  66.     return $translated_text;
  67. }
  68.  
  69. // Logic to figure out if the user has a renewal date and to setup the hooks to show that instead
  70. function wp_renewal_dates_setup() {
  71.     global $current_user, $pmpro_pages;
  72.    
  73.     // in case PMPro is not active
  74.     if(!function_exists('pmpro_getMembershipLevelForUser'))
  75.         return;
  76.    
  77.     // If the user has an expiration date, tell PMPro it is expiring "soon" so the renewal link is shown
  78.     $membership_level = pmpro_getMembershipLevelForUser($current_user->ID);            
  79.     if(!empty($membership_level) && !pmpro_isLevelRecurring($membership_level))
  80.         add_filter('pmpro_is_level_expiring_soon', '__return_true');    
  81.    
  82.     if( is_page( $pmpro_pages[ 'account' ] ) ) {
  83.         // If the user has no expiration date, add filter to change "expiration date" to "renewal date"        
  84.         if(!empty($membership_level) && (empty($membership_level->enddate) || $membership_level->enddate == '0000-00-00 00:00:00'))
  85.             add_filter('gettext', 'change_expiration_date_to_renewal_date', 10, 3);        
  86.        
  87.         // Check to see if the user's last order was with PayPal Express, else assume it was with Stripe.
  88.         // These filters make the next payment calculation more accurate by hitting the gateway
  89.         $order = new MemberOrder();
  90.         $order->getLastMemberOrder( $current_user->ID );
  91.         if( !empty($order) && $order->gateway == 'paypalexpress') {
  92.             add_filter('pmpro_next_payment', array('PMProGateway_paypalexpress', 'pmpro_next_payment'), 10, 3);    
  93.         }else{
  94.             add_filter('pmpro_next_payment', array('PMProGateway_stripe', 'pmpro_next_payment'), 10, 3);    
  95.         }
  96.     }
  97.     add_filter('pmpro_account_membership_expiration_text', 'my_pmpro_expiration_text');    
  98. }
  99. add_action('wp', 'wp_renewal_dates_setup', 11);
  100.  
  101.  
  102. /**
  103.  * Add the following code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations
  104.  * In this example you will learn how to add 3 checkboxes to Paid Memberships Pro Checkout page.
  105.  */
  106. function rh_fields_example_checkbox()
  107. {
  108.     //don't break if Register Helper is not loaded
  109.     if(!function_exists( 'pmprorh_add_registration_field' )) {
  110.         return false;
  111.     }
  112.    
  113.     //define the fields
  114.     $fields = array();
  115.  
  116.     $fields[] = new PMProRH_Field(
  117.         'Accept',                       // input name, will also be used as meta key
  118.         'checkbox',                     // type of field
  119.         array(
  120.             'label' => 'I hereby grant Women Innovating Together permission to use my likeness in a photograph, video, or other digital media (“photo”) in any and all of its publications, including web-based publications, without payment or other consideration.',
  121.             'required'  => true,            // make this field required
  122.                         'profile' => 'true',
  123.         )
  124.     );
  125.     $fields[] = new PMProRH_Field(
  126.                 'Woman',                        // input name, will also be used as meta key
  127.         'checkbox',                     // type of field
  128.         array(
  129.             'label' => 'I am a woman who has an amateur, professional, or supporting role using Claris products',
  130.             'required'  => true,            // make this field required
  131.                         'profile' => 'true',
  132.         )
  133.     );
  134.    
  135.    
  136.     //add the fields into a new checkout_boxes are of the checkout page
  137.     foreach($fields as $field)
  138.         pmprorh_add_registration_field(
  139.             'checkout_boxes',               // location on checkout page
  140.             $field                      // PMProRH_Field object
  141.         );
  142.     //that's it. see the PMPro Register Helper readme for more information and examples.
  143. }
  144. add_action( 'init', 'rh_fields_example_checkbox' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement