Skip to content

Instantly share code, notes, and snippets.

View grayayer's full-sized avatar

Gray Ayer grayayer

View GitHub Profile
@grayayer
grayayer / gist:866f8812c562754c2b401b0c906061fa
Created November 6, 2024 00:43
allow wordpress password protected pages to show users what they're typing in the password field when it's focused
<?php
/**
* Password Peek
*
* Add focus toggle script to password-protected pages, so when the password field is focused, it will show the password.
*
* @package PDXWLF
*/
/**
@grayayer
grayayer / auto-click gift woocommerce subscription
Created December 1, 2020 04:26
WooCommerce Subscription product page with gifted subscriptions checkbox gets auto clicked upon page load.
function auto_select_gift() {
if ( is_single(56669) ) { //enter product id here
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
document.getElementById("gifting_0_option").click(); // Click on the checkbox
});
</script>
<?php
Search for : (.*(\n|$)){2}
alt+R - to toggle regular expression search
alt+ENTER - to select all results
@grayayer
grayayer / user_favorites.js
Last active July 10, 2020 22:17
This is a jquery/javascript that allows us to change the visible status of a "liked" status of an element, then store that preference in a user's browser so that the changed state remains upon returning to the page. This was built specifically for http://moda2.studiok40.com/index-moda.html but can be modified for anyone else's purposes
/** SCRIPTS FOR DESIGNATING WHEN ITEMS ARE LIKED, STORING THAT PREFERENCE,
AND LOADING THOSE PREFERENCES UPON PAGE REFRESH **/
/** when you click on a featured heart, make it liked **/
$(".solution_item .liked_status").click(function(){
// create a variable that references the containing parent of heart just clicked
const self = $(this).parent();
// create a variable that contains just the ID of the parent element
const likedToolID = self.attr("id");
@grayayer
grayayer / woocommerce_conditonal_product_purchase_tracking_code.php
Created May 19, 2020 23:15
this function checks whether the page is the order received page, and if so, checks whether the order contains the bundle product, and if so, outputs the tracking pixel on that page. Put this file in your themes function.php file
/** Add tracking pixel if order contains product ID. Replace 11747 with your specific product ID */
add_action( 'woocommerce_thankyou', 'bundleTracking' );
function bundleTracking(){
/* do nothing if we are not on the appropriate page */
if( !is_wc_endpoint_url( 'order-received' ) || empty( $_GET['key'] ) ) {
return;
}
@grayayer
grayayer / sort-by-date-column.php
Created April 16, 2020 22:33
Add a “Last Modified” Column in WordPress for pages and posts
/** Add a “Last Modified” Column in WordPress for pages and posts **/
// Register the column
function modified_column_register( $columns ) {
$columns['modified_list'] = __( 'Modified', 'my-plugin' );
return $columns;
}
add_filter( 'manage_edit-page_columns', 'modified_column_register' );
add_filter( 'manage_edit-post_columns', 'modified_column_register' );
@grayayer
grayayer / functions.php
Created February 10, 2020 19:52
Shows a message at the WooCommerce cart/checkout displaying how much customer needs to add to get free shipping. Only shows if there are items in cart
/**
* Show a message at the cart/checkout displaying
* how much to go for free shipping.
*/
function wc_free_shipping_incentive_notice() {
if ( ! is_cart() && ! is_checkout() && ( WC()->cart->get_cart_contents_count() == 0 ) ) {
return;
}
@grayayer
grayayer / gist:f939bf4f2be0d631dc51b066bf3b8e19
Last active November 30, 2018 03:57
wp-perf-optimization-without-plugin
/*Update following in your WordPress theme's functions.php file */
// Remove Query String from Static Resources
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
@grayayer
grayayer / add-product-to-cart.php
Created March 3, 2018 00:35 — forked from sc0ttkclark/add-product-to-cart.php
WooCommerce Automatically add product to cart on site visit
<?php
/*
* This code goes into theme functions.php or a custom plugin
*/
/**
* Add product to cart on page load
*/
function add_product_to_cart() {
@grayayer
grayayer / gist:4bd0ce48286969303cb6623c8c654cda
Created May 11, 2017 18:37
hide WP version from scripts and styles
/* Hide WP version strings from scripts and styles
* @return {string} $src
* @filter script_loader_src
* @filter style_loader_src
*/
function fjarrett_remove_wp_version_strings( $src ) {
global $wp_version;
parse_str(parse_url($src, PHP_URL_QUERY), $query);
if ( !empty($query['ver']) && $query['ver'] === $wp_version ) {
$src = remove_query_arg('ver', $src);