Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / my_woocommerce_new_customer_data.php
Created February 2, 2022 11:52
If the POST contains the first_name and last_name fields, add to the customer created through WooCommerce.
<?php
/**
* If the POST contains the first_name and last_name fields, add to the customer created through WooCommerce.
*/
function my_woocommerce_new_customer_data( $new_customer_data ) {
if ( empty( $new_customer_data['first_name'] ) && isset( $_POST['first_name'] ) ) {
$new_customer_data['first_name'] = sanitize_text_field( $_POST['first_name'] );
}
if ( empty( $new_customer_data['last_name'] ) && isset( $_POST['last_name'] ) ) {
$new_customer_data['last_name'] = sanitize_text_field( $_POST['last_name'] );
@kimcoleman
kimcoleman / my_pmpro_widget_display_by_level_id_callback.php
Created February 1, 2022 21:30
Hide widgets by widget area ID based on the user's membership level.
<?php
/**
* Hide widgets by widget area ID based on the user's membership level.
* Update the $hide_sidebars_array with the array of sidebar IDs you want to filter.
* Update the $show_for_levels_array with the array level IDs you want this sidebar visible for.
*/
function my_pmpro_widget_display_by_level_id_callback( $instance, $widget, $args ) {
// Set an array of widget areas by ID to filter.
$hide_sidebars_array = array( 'sidebar-1', 'sidebar-2' );
@kimcoleman
kimcoleman / my_pmpro_affiliate_default_cookie_duration.php
Created January 29, 2022 16:23
Adjust the default value of cookie days when manually adding a new affiliate.
@kimcoleman
kimcoleman / pmpro-columns-grid-payment-method-select-checkout.css
Created January 28, 2022 17:11
Custom CSS for Membership Checkout page with Payment Method Select using CSS Grid: 2 Column Layout for "Account Information" and "Billing Information" sections.
.pmpro-checkout .pmpro_form {
display: -ms-grid;
display: grid;
grid-column-gap: 1em;
-ms-grid-columns: 1 1em 1;
grid-template-columns: 1 1;
grid-template-areas:
"message message"
"pricing pricing"
"user address"
@kimcoleman
kimcoleman / pmpro_show_specific_levels_to_members.html
Created January 22, 2022 13:46
Method to show specific level options to specific members with Paid Memberships Pro.
/* Method to show specific level options to specific members. */
[membership level="1"]
[pmpro_advanced_levels levels="2,3,4"]
[/membership]
[membership level="2"]
[pmpro_advanced_levels levels="5,6,7"]
[/membership]
@kimcoleman
kimcoleman / protected_post_custom_post_thumbnail_html_css.css
Created January 14, 2022 21:47
CSS to accompany the recipe on filtering the featured image and include an overlay if the post is protected.
/* Use this with the recipe here: https://gist.github.com/kimcoleman/faf2cd0a83f3ca7a5c6c368e371ad1f3 */
.pmpro_protected_post_featured_image {
position: relative;
overflow: hidden;
}
.pmpro_protected_post_featured_image img {
filter: grayscale(1) blur(5px);
}
.pmpro_protected_post_blur_mask {
-webkit-box-align: center;
@kimcoleman
kimcoleman / protected_post_custom_post_thumbnail_html.php
Last active January 25, 2022 19:23
Filter the featured image and include an overlay if the post is protected.
<?php
/**
* Filter the featured image and include an overlay if the post is protected.
* Use this with the recipe here: https://gist.github.com/kimcoleman/299bb458310e00d7282c090110c6b4f0
*
* 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.
*
*/
/**
@kimcoleman
kimcoleman / stranger_studios_season_body_class.php
Created December 15, 2021 23:39
Add a season-specific class to the body tag.
<?php
/**
* Add a season-specific class to the body tag.
*
*/
function stranger_studios_season_body_class( $classes ) {
$months_winter = array( 1, 2, 11, 12 );
if ( in_array( date( 'm' ), $months_winter ) ) {
$classes[] = 'body_winter';
}
@kimcoleman
kimcoleman / my_swsales_show_banner_exclude_users_edd_examples.php
Last active June 23, 2022 12:42
Examples for how to hide the banners based on the user's EDD purchase history or role.
<?php
/**
* Examples for how to hide the banners based on the user's EDD purchase history.
*/
function my_swsales_show_banner_exclude_users_edd_examples( $show_banner, $active_sitewide_sale ) {
// Return early if there is no logged in user.
if ( ! is_user_logged_in( ) ) {
return $show_banner;
}
@kimcoleman
kimcoleman / my_set_pmpro_default_country.php
Last active November 19, 2021 16:24
Use the pmpro_default_country filter to pre-set the dropdown at checkout to your country of choice.
<?php
/** Use the pmpro_default_country filter to pre-set the dropdown at checkout to your country of choice.
*
* 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.
*
*/
function my_set_pmpro_default_country( $default_country ) {
// Set country code to "GB" for United Kingdom.
$default_country = "GB";