Skip to content

Instantly share code, notes, and snippets.

View grayayer's full-sized avatar

Gray Ayer grayayer

View GitHub Profile
@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);
@grayayer
grayayer / functions.php
Created April 20, 2017 22:29 — forked from temperatio/functions.php
Woocommerce: Remove related products
/**
* Remove related products
*/
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
@grayayer
grayayer / functions.php
Created April 20, 2017 01:00
remove related products from the bottom of product pages in Woocommerce
/* remove related products from the bottom of product pages in Woocommerce */
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_action( 'woocommerce_after_single_product_summary', 'related_upsell_products', 15 );
function related_upsell_products() {
global $product;
if ( isset( $product ) && is_product() ) {
/*WordPress has a built in function, the_meta(), for outputting all custom fields. But this function is limited in that it doesn't always output all of them. For example, it misses custom fields added by plugins which begin with an _ underscore.
This bit of code uses an alternate function, get_post_custom() which will return all of them, and display all values. Good for debugging.*/
<h3>All Post Meta</h3>
<?php $getPostCustom=get_post_custom(); // Get all the data ?>
<?php
foreach($getPostCustom as $name=>$value) {
@grayayer
grayayer / on-sale-woocommerce-sort.php
Created November 28, 2016 02:40
Order Products by ‘On Sale’ in WooCommerce
add_filter( 'woocommerce_get_catalog_ordering_args', 'wcs_get_catalog_ordering_args' );
function wcs_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'on_sale' == $orderby_value ) {
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
$args['meta_key'] = '_sale_price';
@grayayer
grayayer / The7ChildThemeFunctions.php
Created October 26, 2016 01:12 — forked from thecodepoetry/functions.php
To change default pre selected sidebar position in The7 and Armada
function dt_change_default_sidebar() {
global $DT_META_BOXES;
if ( $DT_META_BOXES ) {
if ( isset($DT_META_BOXES[ 'dt_page_box-sidebar' ]) ) {
$DT_META_BOXES[ 'dt_page_box-sidebar' ]['fields'][0]['std'] = 'left'; // use disabled to disable sidebar
}