Skip to content

Instantly share code, notes, and snippets.

View ipokkel's full-sized avatar

Theuns Coetzee ipokkel

View GitHub Profile
@ipokkel
ipokkel / my-pmprorh-read-only.php
Last active January 8, 2021 07:44
Set Register Helper field to read only for members but not administrators or membership managers with the readonly field option.
<?php
/**
* This recipe creates a custom fields for membership registration
* that is readonly on the user edit profile for members and
* editable by administrators or users with the membership manager role.
*
* This recipe assumes that the registration field is required during checkout.
*
* @requires Register Helper Add On
* @link https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
@dparker1005
dparker1005 / active_users_on_date.sql
Last active July 28, 2020 20:01
Get the users who were active on a specific date (as written, June 1st 2020)
SELECT distinct mu.user_id, u.user_email FROM wp_pmpro_memberships_users AS mu
LEFT JOIN wp_users AS u
ON mu.user_id = u.id
WHERE mu.startdate < "2020-06-01 23:59:59"
AND ( mu.enddate > "2020-06-01 00:00:00" OR mu.enddate = "0000-00-00 00:00:00" OR mu.enddate is NULL )
ORDER BY mu.user_id
@dparker1005
dparker1005 / pmpro_mailchimp_merge_fields.php
Created July 24, 2020 16:57
Creates a new merge field in Mailchimp if one doesn't already exist.
<?php
// Copy from below here...
/*
* Creates a new merge field in Mailchimp if one doesn't already exist.
*/
function my_pmpro_mailchimp_merge_fields( $merge_fields ) {
// Adds a "COMPANY" merge field to Mailchimp.
$merge_fields[] = array('name' => 'COMPANY', 'type' => 'text');
@andrewlimaza
andrewlimaza / Generate username.php
Created July 16, 2020 12:39
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
@kimcoleman
kimcoleman / my_pmprorh_init_user_avatar.php
Last active January 20, 2022 15:46
Allow members to upload their avatar using a Register Helper field during checkout or on the Member Profile Edit page.
<?php
/*
* Allow members to upload their avatar using a Register Helper field during checkout or on the Member Profile Edit page.
*
* Requires: Paid Memberships Pro, Register Helper Add On.
*
* 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/
<?php
/**
* This recipe will convert any Advanced Custom Fields into Register Helper Fields,
* ensuring they display on your checkout or signup form.
*
* 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/
*/
<?php
/**
* This recipe is based off of the below guide but generaes a member number based on the member's level
* https://www.paidmembershipspro.com/generate-a-unique-member-number-for-display-on-membership-account-confirmation-email-and-more/
*
* 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/
*/
@andrewlimaza
andrewlimaza / woo-product-membership-name.php
Created June 17, 2020 11:38
Show the membership level name on single product view WooCommerce. [Paid Memberships Pro]
<?php
/**
* Show membership product name for a WooCommerce product if assigned to a level.
* Add this code to your site by following this example: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_show_level_name_woo_product() {
global $product;
@andrewlimaza
andrewlimaza / redirect-logged-in-non-members-to-levels-page.php
Created May 29, 2020 12:08
Redirect logged-in non-members from account page to levels page. [Paid Memberships Pro]
<?php
/**
* Redirect logged-in non-members from the account page to the levels page.
* Requires Paid Memberships Pro 2.3+
* To add this code to your site visit: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function redirect_logged_in_non_members_to_levels_page() {
// Check if PMPro is installed.
<?php //do not copy
/**
* This recipe removes the parameters for the page that gets created for each order.
* This ensures that only the user's page is created and no other pages for each level are created.
*
* 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/