Skip to content

Instantly share code, notes, and snippets.

View femiyb's full-sized avatar
🏠
Working from home

Femi YB femiyb

🏠
Working from home
View GitHub Profile
@femiyb
femiyb / pmpro-after-expiration-change-membership-levels.php
Last active May 24, 2021 06:52 — forked from pbrocks/pmpro-after-expiration-change-membership-levels.php
Change PMPro membership level upon expiration or cancellation to different respective levels based on member's previous level.
<?php
/**
* When users cancel (are changed to membership level 0) we give them another "cancelled" level.
* Can be used to downgrade someone to a free level when they cancel.
* Will allow members to the "cancel level" to cancel from that though.
*/
function pmpro_after_expiration_change_membership_levels( $level_id, $user_id ) {
// set this to the id of the level you want to give members when they cancel
$last_level_3 = 3;
$last_level_8 = 8;
@femiyb
femiyb / Generate username.php
Created May 17, 2021 16:26 — forked from andrewlimaza/Generate username.php
Generate username from firstname and last name PMPro.
<?php
/**
* This requires billing fields to be enabled at checkout.
* Generate a username from firstname and lastname fields. If name exists will try to generate a random number after the username.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_generate_username_at_checkout() {
//check for level as well to make sure we're on checkout page
@femiyb
femiyb / pmprosus_pmpro_email_data_edit.php
Last active May 18, 2021 10:03
Edit Email Data for PMPro Signup Shortcode
<?php
/**
* Edit the Signup Shortcode password that is generated and emailed to the customer.
* Add this code to your site by following this guide: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
remove_filter('pmpro_email_data', 'pmprosus_pmpro_email_data', 10, 2);
function pmprosus_pmpro_email_data_edit($data, $email) {
@femiyb
femiyb / gist:7ab0435b13fc56131377568bd8ab33d7
Last active April 20, 2021 10:13 — forked from ecline888/gist:c49e29aa60aea35bb4c35c8c0b51e4a0
Add billing address at checkout PaidMemberships Pro
<?php
/**
* This recipe will add billing fields to the checkout. Useful for payment gateways
* that don't have the option to display billing fields.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
@femiyb
femiyb / pmpro-cancel-level.php
Created April 16, 2021 15:05 — forked from greathmaster/pmpro-cancel-level.php
Give members a different level when expiring or cancelling based on their previous level.
/*
When users cancel (are changed to membership level 0) who previously belonged to
level 2 are given level 1 with expiration date of one year.
*/
function my_pmpro_after_change_membership_level($level_id, $user_id)
{
$levelshistory = $wpdb->get_results("SELECT * FROM $wpdb->pmpro_memberships_users WHERE user_id = '$current_user->ID' ORDER BY id DESC");
if($levelshistory && $levelshistory[0]->membership_id == 2 && $level_id == 0)
{
@femiyb
femiyb / pmpro_remove_rhfields_confirmation_email.php
Created April 6, 2021 10:10
Remove Custom fields from Confirmation Email
<?php
/**
* Remove Custom fields from Confirmation Email
* Add code to your site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_remove_rhfields_confirmation_email(){
if ( has_filter( 'pmpro_email_filter', 'pmprorh_pmpro_email_filter' ) ) {
remove_filter( 'pmpro_email_filter', 'pmprorh_pmpro_email_filter', 10, 2 );
@femiyb
femiyb / my_pmpropbc_enqueue_scripts.php
Last active March 30, 2021 10:33 — forked from messica/my_pmpropbc_enqueue_scripts.php
Hide Auto-Renewal Checkbox for Check payment
<?php
/**
* Hide Auto-Renewal Checkbox for Check payment
*/
function my_pmpropbc_enqueue_scripts() {
global $pmpro_pages;
if(is_page($pmpro_pages['checkout'])) {
@femiyb
femiyb / remove-sub-delay-add-on.php
Last active March 30, 2021 10:12 — forked from andrewlimaza/remove-sub-delay-add-on.php
Remove subscription delay for any previous member for PMPro.
<?php
/**
* Once a user checks out for a level, it will add usermeta to the user's account.
* This will then remove any subscription delay for that member in the future, even if the user cancels and then re-signs up.
*/
// Update level meta everytime a user changes their level to ensure they are blocked from subscription delays.
function my_pmpro_trial_used( $level_id, $user_id ) {
update_user_meta( $user_id, "pmpro_trial_level_used", "1" ); // Assume the user has any level.
}
@femiyb
femiyb / pmpro-logout-and-redirect-after-checkout.php
Created March 26, 2021 16:19 — forked from greathmaster/pmpro-logout-and-redirect-after-checkout.php
Log out the user after checkout and redirect them to a custom URL
<?php
// Log user out after check out
function my_pmpro_after_checkout($user_id)
{
wp_logout();
}
add_action('pmpro_after_checkout', 'my_pmpro_after_checkout');
@femiyb
femiyb / my_pmpro_email_headers_bcc_on_recurring_email.php
Last active April 14, 2021 22:43
Forward membership_recurring email to admin
<?php
/*
* Forward membership_recurring email to admin
*/
function my_pmpro_email_headers_bcc_on_recurring_email( $headers, $email ) {
if ( strpos( $email->template, 'membership_recurring' ) !== false ) {
//add bcc
$headers[] = "Bcc:" . "otheremail@domain.com";
}