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 / only_one_discount_code.php
Created January 22, 2020 13:39 — forked from dparker1005/only_one_discount_code.php
Only allows each user to use one discount code.
<?php
/*
Each user can only use one discount code.
Add this to your active theme's functions.php or a custom plugin.
*/
function my_pmpro_check_discount_code($okay, $dbcode, $level_id, $code)
{
global $wpdb, $current_user;
$codes_used = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->pmpro_discount_codes_uses WHERE user_id = '" . $current_user->ID . "'" );
@femiyb
femiyb / my-template-redirect-example.php
Last active January 22, 2020 16:36 — forked from andrewlimaza/my-template-redirect-example.php
Redirect non-members to homepage but allow access to PMPro checkout pages.
<?php
/**
* Redirect non-members (including logged-in non-members) away from restricted pages and to home page.
* This allows non-members to access Paid Memberships Pro checkout/levels pages as well as the default WordPress login page.
*
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_redirect_non_members_example() {
@femiyb
femiyb / redirect-member-away-from-page.php
Last active February 6, 2020 08:49 — forked from andrewlimaza/redirect-member-away-from-page.php
redirect user away from the page if they do not have a specific membership level.
<?php
/**
* This will redirect members with level 1 from site.com/page-slug to the home page.
* Please adjust accordingly and add to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function redirect_member_from_page_x() {
if ( is_page( 'shop' ) && ! pmpro_hasMembershipLevel() ) {
wp_redirect( home_url('login') ); //redirect to home page. Change home_url() to home_url( '/page-slug' ) to redirect to specific page.
@femiyb
femiyb / show-pmpro-address-fields-on-profile.php
Created April 14, 2020 09:27 — forked from pbrocks/show-pmpro-address-fields-on-profile.php
Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page
<?php
/**
* Use PMPro Register Helper to add PMPro Billing Address fields to the edit user page.
*/
/**
* show_pmpro_address_fields_on_edit_profile Grabs the values from the billing fields which get filled in during checkout and displays on User Profile.
*
* @return array Array of Register Helper field objects
*/
function show_pmpro_address_fields_on_edit_profile() {
@femiyb
femiyb / pmpro-remove-user-membership-order-data.php
Last active April 16, 2020 17:36 — forked from JarrydLong/pmpro-remove-user-membership-order-data.php
Removes a user's membership order data either by manually adding in a query param, or when deleting a user through /wp-admin/
<?php
/**
* Remove user order manually by adjusting the ID's in the array, or adding them into a
* query param by setting it to /?reset_test_accounts=true&accounts=2,3
*/
function pmpro_remove_orders( $user_id = null ){
if( isset( $_REQUEST['reset_test_accounts'] ) && $_REQUEST['reset_test_accounts'] == 'true' ){
global $wpdb;
@femiyb
femiyb / my_pmpro_term_template_redirect.php
Last active April 21, 2020 07:22 — forked from strangerstudios/my_pmpro_term_template_redirect.php
Redirect non-members away from CPTs with specific term
<?php
function my_pmpro_term_template_redirect() {
global $post;
//change category and level ID here
if( has_term('PGreen-blog', 'content_type', $post) && 351 == $post->ID && !pmpro_hasMembershipLevel())
{
wp_redirect(pmpro_url('levels'));
exit;
}
}
@femiyb
femiyb / my_gettext_pay_by_check.php
Last active April 24, 2020 13:01 — forked from strangerstudios/my_gettext_pay_by_check.php
Update Pay by Check wording in pmpro-pay-by-check to something else.
<?php
/*
Change "Pay by Check" language to "Pay by Bank"
Add this code to your active theme's functions.php
or a custom plugin.
*/
function my_gettext_pay_by_check($translated_text, $text, $domain)
{
if($domain == "pmpro-pay-by-check" && $text == "Pay by Check")
@femiyb
femiyb / pmpro-south_african-vat.php
Created April 24, 2020 15:59 — forked from travislima/pmpro-south_african-vat.php
Paid Memberships Pro - South African VAT Plugin (DEVELOPING)
<?php
/*
Plugin Name: Paid Memberships Pro - South Africa VAT
Plugin URI: TBA
Description: Apply South Africa VAT to Checkouts with PMPro
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
@femiyb
femiyb / pmpro_custom_teaser_text.php
Created May 11, 2020 11:08 — forked from strangerstudios/pmpro_custom_teaser_text.php
Customize the teaser text (typically set in the advanced options) using filters with Paid Memberships Pro.
/*
Edit Teaser Messages Depending on Content
In the example below, we have 3 levels with IDs 1, 2, and 3. Level 1 is a free level.
Level 2 is a paid level. Level 3 is a higher-tiered paid level.
So each level is an upgrade over the other. All level 2 members have access to level 1 content, etc.
When showing teaser text, we check if the current post is available to free members.
If so, we show a link to register for the free level. If not, we show a link to the paid level.
/*
PMPro percent off discount codes. Adds a text field to the discount code settings to define a percentage off the membership level. This will override any other discount code settings for the level. Currently, only works on initial one-time payments.
*/
function pmpropd_pmpro_discount_code_after_level_settings( $code_id, $level ) {
$percents = pmpro_getDCPDs( $code_id );
if ( ! empty( $percents [ $level->id ] ) ) {
$percent = $percents [ $level->id ];
} else {
$percent = '';