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 / shipping_fields_optional.php
Last active May 5, 2021 15:00 — forked from andrewlimaza/shipping_fields_optional.php
make shipping fields optional PMPro
<?php
// Add this function to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
function pmpro_hide_shipping_fields( $shipping_fields ) {
unset( $shipping_fields['bphone'] );
return $shipping_fields;
}
add_filter( 'pmproship_required_shipping_fields', 'pmpro_hide_shipping_fields' );
@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 / 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 / remove-custom-trial-for-existing-members.php
Last active April 14, 2021 11:10 — forked from andrewlimaza/remove-custom-trial-for-existing-members.php
Remove trial limit for existing members. [Paid Memberships Pro]
<?php
/**
* Remove custom trial for existing members (when existing member changes levels/renews)
* Adjust the level ID on line 15 to match your needs.
* Add this code to your WordPress site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_level_adjustment( $level ) {
// Bail if the user currently doesn't have a membership level.
@femiyb
femiyb / translate-pmpro.php
Last active July 27, 2020 19:12 — forked from andrewlimaza/translate-to-french.php
Translate PMPro
<?php
// Please add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
function my_pmpro_change_text($translated_text, $original_text, $domain) {
switch ( $translated_text ) {
case 'First Name' :
$translated_text = __( 'Change First Name.', 'paid-memberships-pro' );
break;
@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;
}
}
function my_pmproec_pmpro_email_body($body, $email)
{
//must be a confirmation email and checkout template
if(!empty($email->data['membership_id']) && pmproec_isEmailConfirmationLevel($email->data['membership_id']) && strpos($email->template, "checkout") !== false)
{
//get user
$user = get_user_by("login", $email->data['user_login']);
$validated = $user->pmpro_email_confirmation_key;
$url = home_url("?ui=" . $user->ID . "&validate=" . $validated);
//need validation?