Skip to content

Instantly share code, notes, and snippets.

View MaximilianoRicoTabo's full-sized avatar

Maximiliano Rico MaximilianoRicoTabo

  • -
  • Montevideo - La Paloma
  • 07:36 (UTC -03:00)
View GitHub Profile
@MaximilianoRicoTabo
MaximilianoRicoTabo / track-custom-page.php
Last active January 11, 2024 14:26
track a custom page into pmpro-google-analytics
<?php
/**
* track a custom page and its level in pmpro-google-analytics
*
* title:track a custom page and its level.
* layout: snippet
* collection: add-ons, pmpro-google-analytics
* category: analytics, custom page, custom checkout page
* link: TBD
*
@MaximilianoRicoTabo
MaximilianoRicoTabo / asign-level.sql
Created January 5, 2024 21:49
Give all non members WP Users a level based on its role.
#give all non-member WP users level 1 with a specific start and end date set
#change the level (1) below and start (2024-01-01) and end (2024-12-31) dates below and um.meta_value ('%subscriber%') to per your needs
INSERT INTO wp_pmpro_memberships_users (user_id, membership_id, code_id, initial_payment, billing_amount, cycle_number, cycle_period, billing_limit,trial_amount,trial_limit, status, startdate, enddate)
SELECT
u.ID, # ID from wp_users table
1, # id of the level to give users
0, # code id to give users
0, # initial payment to give users
0, # recurring amount to give users
@MaximilianoRicoTabo
MaximilianoRicoTabo / validate_discount_code.php
Last active January 2, 2024 19:59
Validate after checkout the discount code is valid
<?php
/**
* Add a custom validation to the checkout page.
*
* @param bool $pmpro_continue_registration
*/
function my_custom_validations( $pmpro_continue_registration ) {
if ( $pmpro_continue_registration ) {
// Check if the user has the level needed.
if ( ! empty( $_REQUEST['discount_code'] ) && $_REQUEST['discount_code'] == 'F37910BEB5' && ! pmpro_hasMembershipLevel( '6' ) ) {
@MaximilianoRicoTabo
MaximilianoRicoTabo / automatically-apply-discount-code.php
Last active January 2, 2024 17:09
Automatically apply a discount code to Paid Memberships Pro checkout if the user has a specific level.
<?php
/**
* Automatically apply a discount code to Paid Memberships Pro checkout if the user has a specific level ( Interesting for MMPU reasons )
*
* Learn more at https://www.paidmembershipspro.com/automatic-discount-code/
*
* title: Automatically apply discount code at checkout
* layout: snippet-example
* collection: discount-codes
<?php
/**
* Add custom columns to PMPro Courses and Lessons in the PMPro Courses Add On counting users having completed lessons and courses
*
* title: Add custom columns to PMPro Courses and Lessons in the PMPro Courses Add On.
* layout: snippet
* collection: add-ons
* category: wp-list-table
*
* You can add this recipe to your site by creating a custom plugin
@MaximilianoRicoTabo
MaximilianoRicoTabo / filter_email.php
Created November 15, 2023 00:24
filter email to avoid pending notification on pmpro approvals Add On for renewals
<?php
/**
* Adjust default emails to show that the user is active for renewals
*/
function pmpro_email_filter( $email ) {
if( class_exists('PMPro_Approvals') ) {
$email_templates = array( 'checkout_paid', 'checkout_check', 'checkout_express' );
//Get the user from the Email object.
@MaximilianoRicoTabo
MaximilianoRicoTabo / adjust_pmpro_levels_array.php
Last active October 18, 2023 13:34
show hidden levels in special conditions
<?php
/**
* Bring back hidden levels for those users currently having that level or they had recently.
* $hidden_level is the id of the level to bring back.
* $end_date_to_compare is the date to compare to determine how much time ago the user had the level.
*
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function adjusting_the_pmpro_levels_array( $levels ) {
$current_user = wp_get_current_user();
@MaximilianoRicoTabo
MaximilianoRicoTabo / generate-username-from-first-and-last-name-pmpro.php
Last active October 19, 2023 17:37 — forked from andrewlimaza/generate-username-from-email-pmpro.php
Generate a username during checkout for user [Paid Memberships Pro]
<?php
/**
* Generate a username at PMPro checkout from first and last name for users.
* Hide your 'username' field using custom CSS.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_generate_username_at_checkout() {
//check for level as well to make sure we're on checkout page
@MaximilianoRicoTabo
MaximilianoRicoTabo / send-notifications-on-profile-update.php
Created October 11, 2023 21:58
Send a custom notification when a user changes their profile
/**
* Hook into profile update and send a notification to site admin
*
* @param int $user_id The ID of the user being updated
* @param object $old_user_data The object of the user before it was updated.
* @return void
*/
function user_profile_update( $user_id, $old_user_data ) {
if( class_exists( 'PMProEmail' ) ) {
//get the user updated.
@MaximilianoRicoTabo
MaximilianoRicoTabo / php
Created September 21, 2023 20:05
Avoiding Undefined Functions doc update
<?php
/**
*
* https://www.paidmembershipspro.com/avoiding-undefined-function-errors-hooks-filters-custom-code/
*
* SUMMARY of article examples
*
* 1- pmprorh_add_registration_field (Register Helper)
* 2- pmpro_has_membership_access (PMPro core)