Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / modify_woocommerce_demo_store_notice_allow_shortcodes.php
Created June 14, 2022 21:01
Allow shortcodes in the WooCommerce Store Notice.
<?php
/**
* Allow shortcodes in the WooCommerce Store Notice.
*/
function modify_woocommerce_demo_store_notice_allow_shortcodes( $notice_html, $notice ) {
$notice_html = '<div class="woocommerce-store-notice demo_store" style="display:none;">' . do_shortcode( wp_kses_post( $notice ) ) . ' <a href="#" class="woocommerce-store-notice__dismiss-link">' . esc_html__( 'Dismiss', 'woocommerce' ) . '</a></div>';
return $notice_html;
}
add_filter( 'woocommerce_demo_store', 'modify_woocommerce_demo_store_notice_allow_shortcodes', 10, 2 );
@kimcoleman
kimcoleman / modify_woocommerce_format_sale_price.php
Last active June 8, 2022 16:51
Format WooCommerce Sale Prices for Accessibility.
<?php
/**
* Format WooCommerce Sale Prices for Accessibility.
*/
function modify_woocommerce_format_sale_price( $price, $regular_price, $sale_price ) {
$price = '<span class="sr-only">Original price</span> <s>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</s> <span class="sr-only">sale price</span> <ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins>';
return $price;
}
add_filter( 'woocommerce_format_sale_price', 'modify_woocommerce_format_sale_price', 10, 3 );
@kimcoleman
kimcoleman / modify_woocommerce_demo_store_turn_off_date.php
Last active June 8, 2022 13:57
Turn off the WooCommerce Store Notice at a specific date and time.
<?php
/**
* Turn off the WooCommerce Store Notice at a specific date and time.
*/
function modify_woocommerce_demo_store_turn_off_date( $notice_html ) {
// Set the current date variable.
$current_date = date( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
// Change this line to set the store notice end date and time variable.
$end_date = '2022-06-08 10:00:00';
@kimcoleman
kimcoleman / modify_woocommerce_demo_store_non_users_only.php
Created June 8, 2022 13:49
Show WooCommerce Store Notice to Not Logged In Visitors Only.
<?php
/**
* Show WooCommerce Store Notice to Not Logged In Visitors Only.
*/
function modify_woocommerce_demo_store_non_users_only( $notice_html ) {
if ( is_user_logged_in() ) {
return '';
}
return $notice_html;
}
@kimcoleman
kimcoleman / modify_woocommerce_demo_store_customers_only.php
Last active June 8, 2022 15:45
Show WooCommerce Store Notice to Logged In Previous Customers Only.
<?php
/**
* Show WooCommerce Store Notice to Logged In Previous Customers Only.
*/
function modify_woocommerce_demo_store_customers_only( $notice_html ) {
if ( ! is_user_logged_in() ) {
return '';
}
// Get the user object.
@kimcoleman
kimcoleman / use_feather_icons_in_wordpress.php
Last active May 21, 2022 11:12
How to use Feather Icons (https://feathericons.com/) in your WordPress site.
<?php
/**
* Use Feather Icons (https://feathericons.com/) in your WordPress site.
*
* First, save a copy of feather.min.js to a custom plugin.
* Get it here: https://unpkg.com/feather-icons
*
*/
// Enqueue the Feather script file.
@kimcoleman
kimcoleman / my_memberlite_custom_color_mods.php
Created May 5, 2022 11:49
Memberlite filters to set custom colors for specific pages.
<?php
/**
* Memberlite filters to set custom colors for specific pages.
*/
// Filter the primary color on a page with the slug 'free'.
function my_memberlite_custom_color_primary( $current_mod ) {
if ( ! is_page( 'free' ) ) {
return $current_mod;
}
@kimcoleman
kimcoleman / my_pmpro_refund_reason.php
Created April 28, 2022 10:15
Add an order meta field for "Refund Reason" so admin can track why people are asking for a refund.
<?php
/**
* Add an order meta field for "Refund Reason" so admin can track
* why people are asking for a refund.
*/
function my_pmpro_refund_reason_after_order_settings( $order ) {
if ( empty( $order->id ) ) {
// This is a new order.
return;
}
@kimcoleman
kimcoleman / my_bua_bp_avatar.php
Created April 25, 2022 15:54
Filter to use the Basic User Avatar on the BuddyPress Profile.
<?php
/**
* Filter to use the Basic User Avatar on the BuddyPress Profile.
*/
function my_bua_bp_avatar( $image, $params ) {
// Determine if user has a local avatar
$local_avatar = get_user_meta( $params['item_id'], 'basic_user_avatar', true );
if ( empty( $local_avatar ) ) {
return $image;
@kimcoleman
kimcoleman / my_habfna_show_admin_bar_roles.php
Created April 10, 2022 11:30
Filter to show WordPress Toolbar for Editor Role using the Hide Admin Bar From Non-Admins plugin.
<?php
/**
* Filter to show WordPress Toolbar for Editor Role using the
* Hide Admin Bar From Non-Admins plugin.
* https://wordpress.org/plugins/hide-admin-bar-from-non-admins/
*
*/
function my_habfna_show_admin_bar_roles( $habfna_show_admin_bar_roles ) {
$habfna_show_admin_bar_roles[] = 'editor';
return $habfna_show_admin_bar_roles;