Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Lima andrewlimaza

View GitHub Profile
@andrewlimaza
andrewlimaza / hide-shipping-method-wholesale-customers-for-woo.php
Last active Aug 10, 2020
Hide shipping method for non-wholesale customers WooCommerce.
View hide-shipping-method-wholesale-customers-for-woo.php
<?php
/**
* Removes shipping methods for non-wholesale customers.
* Please be sure to clear your WooCommerce store's cache.
* Adjust 'flat_rate:2' to match that of your wholesale shipping method.
*/
function my_wcs_remove_shipping_non_wholesale( $rates, $package ){
global $current_user;
@andrewlimaza
andrewlimaza / hide-payment-option-wcs-for-woo.php
Created Aug 10, 2020
Hide payment option for Wholesale Customers For WooCommerce Plugin.
View hide-payment-option-wcs-for-woo.php
<?php
/**
* Hide payment gateways for wholesale customers.
* Add this code to your site via a custom plugin or the Code Snippets Plugin.
* Adjust line 18 with payment gateway ID's you wish to hide from wholesale customers.
* Reference: https://yoohooplugins.com/woocommerce-wholesale-customers-payment-gateway/
*/
function yoohoo_wcs_hide_gateways( $available_gateways ) {
global $current_user;
@andrewlimaza
andrewlimaza / Force-billing-fields-for-authorize-net.php
Created Aug 4, 2020
Force billing fields for Paid Memberships Pro for specific levels.
View Force-billing-fields-for-authorize-net.php
<?php
/**
* Force billing fields for specific levels (line 9) for Authorize.net and Paid Memberships Pro.
* Add this code to your site by following these steps: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function al_force_billing_fields_pmpro_authorize_net( $fields ) {
$levels_array = array( 1,3 ); // change this to levels that require billing fields.
@andrewlimaza
andrewlimaza / rh-file-upload-members-csv.php
Created Jul 31, 2020
Add Register Helper File Upload Field to Member's CSV Export
View rh-file-upload-members-csv.php
<?php
/**
* Add the full URL of a file upload field to member export CSV.
* Adjust the 'my_image' value with the relevant Register Helper field key.
* You can add this code snippet to your WordPress site following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Add a custom column to the CSV export.
function my_pmpro_members_list_csv_extra_columns ( $columns ) {
$columns["uploaded"] = "my_pmpro_members_list_uploaded";
@andrewlimaza
andrewlimaza / add-user-id-to-pmpro-email.php
Created Jul 20, 2020
Add !!user_id!! to Paid Memberships Pro Emails
View add-user-id-to-pmpro-email.php
<?php
/**
* Add's !!user_id!! variable to all Paid Memberships Pro emails.
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_email_data_example( $data, $email ) {
$user = get_user_by( "login", $data['user_login'] );
$data['user_id'] = $user->ID; //adjust 'user_id' for the variable you want to use instead.
@andrewlimaza
andrewlimaza / Generate username.php
Created Jul 16, 2020
Generate username from firstname and last name PMPro.
View Generate username.php
<?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
@andrewlimaza
andrewlimaza / generate-username-from-email-pmpro.php
Created Jul 15, 2020
Generate a username during checkout for user [Paid Memberships Pro]
View generate-username-from-email-pmpro.php
<?php
/**
* Generate a username at PMPro checkout from email 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_generate_username_at_checkout() {
//check for level as well to make sure we're on checkout page
@andrewlimaza
andrewlimaza / add-membership-level-name-email-template.php
Created Jul 6, 2020
Add !!membership_level_name!! to all email templates for Paid Memberships Pro Email Template Add On.
View add-membership-level-name-email-template.php
<?php
/**
* Add attribute !!membership_level_name!! to all email templates for Paid Memberships Pro Email Templates Admin Editor.
* Follow this guide to add custom code to your WordPress site - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_email_data($data, $email) {
if ( ! isset( $data['membership_level_name'] ) ) {
$user = get_user_by( 'email', $data['user_email'] );
$level = pmpro_getMembershipLevelForUser( $user->ID );
@andrewlimaza
andrewlimaza / pmpro-reset-views-visits-login-reports.sql
Created Jul 2, 2020
Reset Views, Visits and Login report data for Paid Memberships Pro.
View pmpro-reset-views-visits-login-reports.sql
/**
* Ensure your table names match exactly. Change the prefix 'wp_' if needed.
* Run simulation query first before executing this query.
* Have a full database backup.
*/
DELETE FROM `wp_options` WHERE `option_name` = 'pmpro_views';
DELETE FROM `wp_options` WHERE `option_name` = 'pmpro_logins';
DELETE FROM `wp_options` WHERE `option_name` = 'pmpro_visits';
@andrewlimaza
andrewlimaza / remove-pmpro-series-filter.php
Created Jun 29, 2020
Remove PMPro Series filter for posts to use default restricted content messages.
View remove-pmpro-series-filter.php
<?php
/**
* Remove PMPro Series (This post belongs to series X) message. Show default content restriction instead.
* Follow this guide to add code to your WordPress site: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_remove_series_filter() {
remove_filter( 'pmpro_non_member_text_filter', 'pmpros_pmpro_text_filter' );
remove_filter( 'pmpro_not_logged_in_text_filter', 'pmpros_pmpro_text_filter' );
}
You can’t perform that action at this time.