Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / my_custom_memberlite_woocommerce_hooks.php
Created January 31, 2024 12:58
Add a sidebar to the entire WooCommerce shop and product pages using the Memberlite theme.
<?php
function my_custom_memberlite_woocommerce_hooks() {
// Remove Memberlite hooks
remove_action( 'woocommerce_before_main_content', 'memberlite_woocommerce_before_main_content', 10 );
remove_action( 'woocommerce_after_main_content', 'memberlite_woocommerce_after_main_content', 10 );
// Add custom WooCommerce hooks
add_action( 'woocommerce_before_main_content', 'my_custom_memberlite_woocommerce_before_main_content', 10 );
add_action( 'woocommerce_after_main_content', 'my_custom_memberlite_woocommerce_after_main_content', 10 );
@kimcoleman
kimcoleman / my_pmpro_member_directory_sql_search_where_username_display_name_only.php
Last active December 21, 2023 20:36
Only search the PMPro Member Directory for matching usernames or display names.
<?php
/**
* Only search the PMPro Member Directory for matching usernames or display names.
*
* 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/
*/
function my_pmpro_member_directory_sql_search_where_username_display_name_only( $sql_search_where, $s ) {
@kimcoleman
kimcoleman / my_sws_apply_sitewide_sales_discount_to_live_price.php
Last active November 18, 2023 19:11
Sitewide Sales compatibility with RightPress Product Prices - Live Update.
<?php
/**
* Sitewide Sales compatibility with RightPress Product Prices - Live Update.
*/
function my_sws_apply_sitewide_sales_discount_to_live_price($price, $product) {
// Return early if Sitewide Sales is not active.
if ( ! defined ( 'SWSALES_VERSION' ) ) {
return $price;
}
@kimcoleman
kimcoleman / pmpro-tag-delete-inactive-users.php
Last active October 31, 2023 12:06 — forked from ideadude/tag_and_delete_inactive_users.php
Script to tag and delete inactive PMPro Members and users from WordPress.
<?php
/**
* Script to locate, tag, export, then delete inactive users in your Paid Memberships Pro / WordPress website.
*
* Once this snippet is in the site, admins can run the process by visiting /?delete_inactive_users=1 in the WordPress admin.
* Always back up user data before running any bulk delete script and remove this code after the process is done.
*/
function my_pmpro_tag_inactive_users() {
if ( ! defined( 'PMPRO_VERSION' ) ) {
exit;
@kimcoleman
kimcoleman / my_pmpro_has_membership_access_on_date.php
Last active October 30, 2023 11:36
Filter to only allow access to a protected post by post ID after a specific calendar date.
<?php
/**
* Filter to only allow access to a protected post by post ID after a specific calendar date.
*/
function my_pmpro_has_membership_access_on_date( $hasaccess, $post, $user ) {
// If they already don't have access, return.
if ( ! $hasaccess ) {
return $hasaccess;
}
@kimcoleman
kimcoleman / my-custom-page-template.php
Created October 27, 2023 11:33
An example template that uses the pmpro_has_membership_access function to protect content.
<?php
/**
* Template Name: My Custom Template
*
* An example template that uses the pmpro_has_membership_access function to protect content.
*
*/
get_header(); ?>
@kimcoleman
kimcoleman / add-credit-card-image-to-checkout.php
Last active October 12, 2023 20:10 — forked from andrewlimaza/add-credit-card-image-to-checkout.php
Display credit card logos before the submit button on the Paid Memberships Pro Membership Checkout page.
<?php
/**
* Display credit card logos before the submit button on the Paid Memberships Pro Membership Checkout page.
*
* Download the icons from https://www.paidmembershipspro.com/add-credit-card-and-paypal-logos-to-checkout/
* Place the image file in the correct location according to your customizations structure.
*/
function pmpro_add_my_logos_to_checkout(){
global $pmpro_level;
@kimcoleman
kimcoleman / export_woocommerce_subscription_user_data.txt
Created August 7, 2023 17:38
MySQL command to export WooCommerce subscription data, including User ID, Product, and Next Payment Date
SELECT
p.ID as 'Subscription ID',
pm1.meta_value as 'User ID',
oitems.order_item_name as 'Product',
pm2.meta_value as 'Next Payment Date'
FROM wp_posts p
INNER JOIN wp_postmeta pm1 ON pm1.post_id = p.ID
INNER JOIN wp_postmeta pm2 ON pm2.post_id = p.ID
INNER JOIN wp_woocommerce_order_items oitems ON oitems.order_id = p.ID
WHERE
@kimcoleman
kimcoleman / common-blocks-theme-unit-test.html
Last active June 14, 2023 11:50
Theme Unit Test - Common Blocks Data
<!-- wp:paragraph -->
<p>The Common category includes the following blocks:<em> Paragraph, image, headings, list, gallery, quote, audio, cover, video.</em></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>The paragraph block is the default block type.&nbsp; It should not have any alignment of any kind. It should just flow like you would normally expect. Nothing fancy. Just straight up text, free flowing, with love.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>This paragraph is left aligned.</p>
@kimcoleman
kimcoleman / my_swsales_hide_from_premium_members.php
Created February 7, 2023 18:07
Hide the active sale from users with level ID 1, 2, or 3.
<?php
/**
* Hide the active sale from users with level ID 1, 2, or 3.
*/
function my_swsales_hide_from_premium_members( ) {
// Return early if this is the admin.
if ( is_admin() ) {
return;
}