Created
August 23, 2017 21:49
-
-
Save eighty20results/69c1718d528c028a0d2c98d6d777e702 to your computer and use it in GitHub Desktop.
Customization: Prorated Expiring membership for @ajac036
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: PMPro Customizations: Membership proration | |
Plugin URI: https://eighty20results.com/paid-memberships-pro/do-it-for-me/ | |
Description: Prorate price for Level ID 5 memberships based on month of the year when the user signs up | |
Version: 1.0 | |
Author: Eighty / 20 Results by Wicked Strong Chicks, LLC <[email protected]> | |
Author URI: https://eighty20results.com/thomas-sjolshagen/ | |
License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
License: GPLv2 or later | |
* Copyright (C) 2017 Thomas Sjolshagen - Eighty / 20 Results by Wicked Strong Chicks, LLC | |
* | |
* This program is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License | |
* as published by the Free Software Foundation; either version 2 | |
* of the License, or (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
*/ | |
class ajaCustomizations { | |
/** | |
* @var null|ajaCustomizations | |
*/ | |
private static $instance = null; | |
/** | |
* ajaCustomizations constructor. | |
* | |
* @access private | |
*/ | |
private function __construct() { | |
} | |
/** | |
* Configure the membership level price, based on the checkout month. | |
* | |
* User signs up in September: Pay 120.00 | |
* User signs up in October: Pay 110.00 | |
* User signs up any other month: Pay 100.00 | |
* | |
* @param stdClass $level | |
* | |
* @return stdClass | |
*/ | |
public function configure_checkout_level( $level ) { | |
if ( isset($level->id) && 5 === intval( $level->id ) ) { | |
$this_month = date_i18n( 'n', current_time( 'timestamp' ) ); | |
// Set amount based on which month it is when the user is signing up for this level (level 5) | |
switch ( $this_month ) { | |
case 9: | |
$level->initial_payment = 120.00; | |
break; | |
case 10: | |
$level->initial_payment = 110.00; | |
break; | |
default: | |
$level->initial_payment = 100.00; | |
} | |
} | |
return $level; | |
} | |
/** | |
* Load required action hooks / filter hooks | |
*/ | |
public function load_hooks() { | |
add_filter( 'pmpro_checkout_level', array( $this, 'configure_checkout_level' ), 10, 1 ); | |
} | |
/** | |
* Initialize the class & return instance | |
* | |
* @return ajaCustomizations|null | |
*/ | |
public static function get_instance() { | |
if ( is_null( self::$instance ) ) { | |
self::$instance = new self; | |
self::$instance->load_hooks(); | |
} | |
return self::$instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment