Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: PMPro Customizations
- Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/
- Description: Customizations for my Paid Memberships Pro Setup
- Version: .1
- Author: Paid Memberships Pro
- Author URI: https://www.paidmembershipspro.com
- */
- //Now start placing your customization code below this line
- /**
- * 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.
- * Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
- */
- function show_renewal_link_after_X_days( $r, $level ) {
- if ( empty( $level->enddate ) ) {
- return false;
- }
- $days = 60; // Change this to value.
- // Are we within the days until expiration?
- $now = current_time( 'timestamp' );
- if ( $now + ( $days * 3600 * 24 ) >= $level->enddate ) {
- $r = true;
- } else {
- $r = false;
- }
- return $r;
- }
- add_filter( 'pmpro_is_level_expiring_soon', 'show_renewal_link_after_X_days', 10, 2 );
- /**
- * Show next payment date under 'Expiration' field in PMPro account page.
- * Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
- * Works for PayPal Express and Stripe payment gateways.
- * www.paidmembershipspro.com
- */
- // Change the expiration text to show the next payment date instead of the expiration date
- // This hook is setup in the wp_renewal_dates_setup function below
- function my_pmpro_expiration_text($expiration_text) {
- global $current_user;
- $next_payment = pmpro_next_payment();
- if( $next_payment ){
- $expiration_text = date_i18n( get_option( 'date_format' ), $next_payment );
- }
- return $expiration_text;
- }
- // Change "expiration date" to "renewal date"
- // This hook is setup in the wp_renewal_dates_setup function below
- function change_expiration_date_to_renewal_date($translated_text, $original_text, $domain) {
- if($domain === 'paid-memberships-pro' && $original_text === 'Expiration')
- $translated_text = 'Renewal Date';
- return $translated_text;
- }
- // Logic to figure out if the user has a renewal date and to setup the hooks to show that instead
- function wp_renewal_dates_setup() {
- global $current_user, $pmpro_pages;
- // in case PMPro is not active
- if(!function_exists('pmpro_getMembershipLevelForUser'))
- return;
- // If the user has an expiration date, tell PMPro it is expiring "soon" so the renewal link is shown
- $membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
- if(!empty($membership_level) && !pmpro_isLevelRecurring($membership_level))
- add_filter('pmpro_is_level_expiring_soon', '__return_true');
- if( is_page( $pmpro_pages[ 'account' ] ) ) {
- // If the user has no expiration date, add filter to change "expiration date" to "renewal date"
- if(!empty($membership_level) && (empty($membership_level->enddate) || $membership_level->enddate == '0000-00-00 00:00:00'))
- add_filter('gettext', 'change_expiration_date_to_renewal_date', 10, 3);
- // Check to see if the user's last order was with PayPal Express, else assume it was with Stripe.
- // These filters make the next payment calculation more accurate by hitting the gateway
- $order = new MemberOrder();
- $order->getLastMemberOrder( $current_user->ID );
- if( !empty($order) && $order->gateway == 'paypalexpress') {
- add_filter('pmpro_next_payment', array('PMProGateway_paypalexpress', 'pmpro_next_payment'), 10, 3);
- }else{
- add_filter('pmpro_next_payment', array('PMProGateway_stripe', 'pmpro_next_payment'), 10, 3);
- }
- }
- add_filter('pmpro_account_membership_expiration_text', 'my_pmpro_expiration_text');
- }
- add_action('wp', 'wp_renewal_dates_setup', 11);
- /**
- * Add the following code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations
- * In this example you will learn how to add 3 checkboxes to Paid Memberships Pro Checkout page.
- */
- function rh_fields_example_checkbox()
- {
- //don't break if Register Helper is not loaded
- if(!function_exists( 'pmprorh_add_registration_field' )) {
- return false;
- }
- //define the fields
- $fields = array();
- $fields[] = new PMProRH_Field(
- 'Accept', // input name, will also be used as meta key
- 'checkbox', // type of field
- array(
- '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.',
- 'required' => true, // make this field required
- 'profile' => 'true',
- )
- );
- $fields[] = new PMProRH_Field(
- 'Woman', // input name, will also be used as meta key
- 'checkbox', // type of field
- array(
- 'label' => 'I am a woman who has an amateur, professional, or supporting role using Claris products',
- 'required' => true, // make this field required
- 'profile' => 'true',
- )
- );
- //add the fields into a new checkout_boxes are of the checkout page
- foreach($fields as $field)
- pmprorh_add_registration_field(
- 'checkout_boxes', // location on checkout page
- $field // PMProRH_Field object
- );
- //that's it. see the PMPro Register Helper readme for more information and examples.
- }
- add_action( 'init', 'rh_fields_example_checkbox' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement