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_coupons_enabled.php
Created June 23, 2022 11:10
Hide the Coupon field on WooCommerce cart page.
<?php
/**
* Hide the Coupon field on WooCommerce cart page.
*/
function my_woocommerce_coupons_enabled( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
}
@kimcoleman
kimcoleman / my_woocommerce_apply_cart_coupon_in_url.php
Created June 23, 2022 11:10
Apply a WooCommerce discount code to cart via URL parameter.
<?php
/**
* Apply a WooCommerce discount code to cart via URL parameter.
* This code is adapted from: https://www.webroomtech.com/apply-coupon-via-url-in-woocommerce/
*/
function my_woocommerce_apply_cart_coupon_in_url() {
// Return early if WooCommerce or sessions aren't available.
if ( ! function_exists( 'WC' ) || ! WC()->session ) {
return;
}
@kimcoleman
kimcoleman / my_reusable_blocks_admin_menu.php
Created June 16, 2022 10:32
Add an admin menu link for Reusable Blocks
<?php
/**
* Add an admin menu link for Reusable Blocks
*/
function my_reusable_blocks_admin_menu() {
add_menu_page( 'Reusable Blocks', 'Reusable Blocks', 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22 );
}
add_action( 'admin_menu', 'my_reusable_blocks_admin_menu' );
@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;
}