Skip to content

Instantly share code, notes, and snippets.

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

Ronald Huereca ronalfy

🏠
Working from home
View GitHub Profile
@ronalfy
ronalfy / pmpro-redirect-user-after-login.php
Created March 11, 2020 15:33
Paid Memberships Pro Redirect User After Login
<?php
function pmpro_redirect_after_login( $redirect_to, $request, $user ) {
if ( ! empty( $user ) && ! empty( $user->ID ) && function_exists( 'pmpro_getMembershipLevelForUser' ) ) {
$level = pmpro_getMembershipLevelForUser( $user->ID );
if ( 1 == $level ) {
$redirect_to = home_url();
}
}
return $redirect_to;
}
@ronalfy
ronalfy / pmpro-text-replacement-pmpro-account-shortcode.php
Created March 6, 2020 22:18
Paid Memberships Pro Text Replacement for pmpro_account Shortcode
<?php
function pmpro_level_cost_text_son( $text ) {
$text = str_replace( ' maintenant', '', $text );
return $text;
}
add_filter( 'pmpro_level_cost_text', 'pmpro_level_cost_text_son', 10, 1 );
@ronalfy
ronalfy / pmpro-sponsored-add-on-tre.php
Created March 6, 2020 17:14
Paid Memberships Pro Sponsored Add On
<?php
global $pmprosm_sponsored_account_levels;
$pmprosm_sponsored_account_levels = array(
6 => array(
'main_level_id' => 6, //redundant but useful
'sponsored_level_id' => array(7), //array or single id
'seats' => 100
),
);
@ronalfy
ronalfy / pmpro-invoice-code-helfer.php
Created March 6, 2020 00:58
Paid Memberships Pro Invoice Code
<?php
function pmpro_invoice_code_helfer( $code ) {
$invoice_code = get_option( 'pmpro_helfer_invoice_code', array() );
if ( empty( $invoice_code ) ) {
$invoice_code = array(
'prefix' => 'IAW',
'increment' => 1,
);
update_option( 'pmpro_helfer_invoice_code', $invoice_code );
}
@ronalfy
ronalfy / pmpro-smk-renew-message.php
Created March 6, 2020 00:10
Paid Memberships Pro Renew Message to User
<?php
function pmpro_renew_smk() {
if ( ! is_user_logged_in() ) {
return;
}
?>
<div id="custom_renew_message" class="alert">This is a custom renew message shown to the user.</div>
<?php
}
add_action( 'pmpro_checkout_after_level_cost', 'pmpro_renew_smk' );
@ronalfy
ronalfy / pmpro-rh-ci-fields.php
Created March 6, 2020 00:01
Paid Memberships Pro Register Helper Company Information Fields
<?php
// We have to put everything in a function called on init, so we are sure Register Helper is loaded.
function pmpro_register_field_trialsofg_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
pmprorh_add_checkout_box( 'company', 'Company Information' );
// Define the fields.
@ronalfy
ronalfy / pmpro-rh-ec-fields.php
Created March 5, 2020 23:34
Paid Memberships Pro Register Helper Adding Emergency Contact Fields
<?php
// We have to put everything in a function called on init, so we are sure Register Helper is loaded.
function pmpro_register_field_peakbagger_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
pmprorh_add_checkout_box( 'contact', 'Contact Information' );
pmprorh_add_checkout_box( 'emergency', 'Emergency Contact Information' );
@ronalfy
ronalfy / My_PMPro_Directory_Widget.php
Last active March 23, 2020 14:41 — forked from dparker1005/My_PMPro_Directory_Widget.php
Add widget to Member Directory page to filter results.
<?php
/**
* Plugin Name: My PMPro Directory Widget
* Description: Add widget to Member Directory page to filter results.
*/
class My_PMPro_Directory_Widget extends WP_Widget {
/**
* Sets up the widget
*/
@ronalfy
ronalfy / pmpro-hide-invite-code-with-approvals-add-on.php
Created March 5, 2020 15:08
Paid Memberships Pro - Hide Membership Invite Code with Approvals Add On
<?php
function pmpro_invite_approval_message() {
if ( is_user_logged_in() ) {
global $current_user;
$user_id = $current_user->ID;
if ( ! PMPro_Approvals::isApproved( $user_id, 1 ) ) { // 1 is the membership level.
remove_filter( "pmpro_confirmation_message", "pmproio_pmpro_confirmation_message" );
remove_filter('the_content', 'pmproio_the_content_account_page', 20, 1);
}
}
@ronalfy
ronalfy / pmpro-prorated-expiration.php
Created March 4, 2020 18:53
Paid Memberships Pro: Prorated Amount Based on Current Time and Beginning of Next Year
<?php
function pmpro_prorated_checkout_level( $level ) {
// 5 is the membership level ID.
if ( 5 === absint( $level->id ) ) {
$price_per_day = $level->initial_payment / 365.2425; // 365.2425 is the days in a year
// Get timestamp for end of year and current timestamp.
$end_date_timestamp = strtotime( 'first day of january next year' );
$current_date_timestamp = time();