Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_gettext_pmprowc_changes.php
Created September 25, 2018 18:51
Change the default text for the one-membership-product-per-cart warning in PMPro WooCommerce.
<?php
/**
* Change the default text for the one-membership-product-per-cart warning in PMPro WooCommerce.
* Add this code to a custom plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_gettext_pmprowc_changes( $translated_text, $text, $domain ) {
if( $domain == "pmpro-woocommerce" && $text == "You may only add one membership to your %scart%s." ) {
$translated_text = "Include the %stwo percent-s strings%s, which will add the start and end a tags.";
}
@ideadude
ideadude / pmpro_btc_currency_format.php
Created November 2, 2018 00:35
Add a BTC currency to Paid Memberships Pro
/**
* Add a BTC currency to Paid Memberships Pro
* Add this code into a custom plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_btc_currency_format( $pmpro_currencies ) {
$pmpro_currencies['BTC'] = array(
'name' => __( 'Bitcoin', 'paid-memberships-pro' ),
'decimals' => '8',
'thousands_separator' => '',
'decimal_separator' => '.',
@ideadude
ideadude / set_request_level_on_sitewide_sales_pages.php
Last active November 5, 2018 13:28
Set the $_REQUEST['level'] var early on specific URLs to help other PMPro Customizations
/**
* We need to set $_REQUEST['level'] early on our
* sitewide sales pages to support other customizations.
* We can't use is_page because WP isn't fully setup yet.
* Update the $sitewide_sales_pages and $default_level_id as needed.
* Add to a custom plugin.
*/
function set_request_level_on_sitewide_sales_pages() {
$sitewide_sales_pages = array(
'blackfriday',
@ideadude
ideadude / override_pricing_fields_on_sitewide_sales_pages.php
Last active November 5, 2018 12:32
Hide the PMPro pricing box at checkout using the new pmpro_include_pricing_fields filter.
/**
* Hide the PMPro pricing box at checkout
* and replace with our own.
*
* Require PMPro v1.9.5.6+ and PMPro Sitewide Sales v1.0+
* Add this into a custom plugin.
*/
function override_pricing_fields_on_sitewide_sales_pages( $include_pricing_fields ) {
global $wpdb, $pmpro_level;
@ideadude
ideadude / pmpro_check_for_deprecated_plugins.php
Created December 6, 2018 21:46
A general purpose check for deprecated add ons.
/**
* Check for merged plugins that should be deactivated.
*/
function pmpro_check_for_deprecated_plugins() {
$pmpro_deprecated_plugins = array(
'pmpro-better-logins-report/pmpro-better-logins-report.php' => 'Better Logins Report',
);
$plugins_to_deactivate = array();
foreach( $pmpro_deprecated_plugins as $plugin_path => $plugin_name ) {
@ideadude
ideadude / pmpro-register-helper-fields.php
Last active April 7, 2021 03:53
Who referred you to our site? field for PMPro Register Helper
<?php
/*
Plugin Name: Paid Memberships Pro - Custom Register Helper Fields
Plugin URI: https://www.paidmembershipspro.com/documentation/register-helper-documentation/code-examples/
Description: Register Helper Fields
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
@ideadude
ideadude / my_disable_stripe_api_next_payment_date.php
Created December 12, 2018 17:22
Keep pmpro_next_payment_date() from using the Stripe API.
/**
* Keep pmpro_next_payment_date() from using the Stripe API.
* Instead, the next payment date will be calculated based on
* the date of the last order in PMPro.
* This will be inaccurate in some cases with regards to trials,
* but avoids issues where Stripe is giving the wrong "next payment"
* date when payments fail.
*/
function my_disable_stripe_api_next_payment_date( $next_payment_date ) {
// remove this filter which may run later
@ideadude
ideadude / test_set_expiration_dates.php
Last active February 22, 2023 18:56
Testing the pmprosed_fixDate() function of PMPro Set Expiration Dates
/**
* Testing the pmprosed_fixDate function.
* 1. Make sure PMPro and PMPro Set Expiration Dates is active.
* 2. Add this code to a custom plugin.
* 3. Visit ?test_date_functions=1 to a URL
* 4. Remember to remove the code when done.
*/
function test_set_expiration_dates() {
if( empty( $_REQUEST['test_date_functions'] ) ) {
return;
@ideadude
ideadude / test_braintree_webhook.php
Last active March 5, 2021 16:37
Testing the Braintree Webhook with PMPro v2.0+
<?php
/**
* Add this function into a customizations plugin
* and then visit /?test_braintree_webhook from a browser.
*/
function init_test_braintree_webhook() {
if(!empty($_REQUEST['test_braintree_webhook'])) {
define('PMPRO_BRAINTREE_WEBHOOK_DEBUG', true);
$gateway = new PMProGateway_braintree();
@ideadude
ideadude / update_pmpro_db_decimals.sql
Last active January 9, 2019 11:44
Update decimal fields in the PMPro database tables to support more decimals, e.g. Bitcoin
# Avoid errors in MySQL 5.7
UPDATE wp_pmpro_memberships_users SET enddate = NULL WHERE CAST(enddate AS CHAR(20)) = '0000-00-00 00:00:00';
# Fix membership_levels table
ALTER TABLE `wp_pmpro_membership_levels` MODIFY `initial_payment` decimal(18,8);
ALTER TABLE `wp_pmpro_membership_levels` MODIFY `billing_amount` decimal(18,8);
ALTER TABLE `wp_pmpro_membership_levels` MODIFY `trial_amount` decimal(18,8);
# Fix memberships_users table
ALTER TABLE `wp_pmpro_memberships_users` MODIFY `initial_payment` decimal(18,8);