Skip to content

Instantly share code, notes, and snippets.

View grayayer's full-sized avatar

Gray Ayer grayayer

View GitHub Profile
@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
}
@grayayer
grayayer / plugin-name.php
Created October 10, 2016 22:59
Disable a plugin's check for updates - useful when you've modified the plugin directly (don't do that though)
add_filter( 'http_request_args', 'dm_prevent_update_check', 10, 2 );
function dm_prevent_update_check( $r, $url ) {
if ( 0 === strpos( $url, 'http://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[$my_plugin] );
unset( $plugins->active[array_search( $my_plugin, $plugins->active )] );
$r['body']['plugins'] = serialize( $plugins );
}
return $r;
@grayayer
grayayer / functions.php
Last active October 7, 2016 21:18 — forked from BFTrick/functions.php
Change WooCommerce Email Styles
<?php
add_filter( 'woocommerce_email_styles', 'patricks_woocommerce_email_styles' );
function patricks_woocommerce_email_styles( $css ) {
$css .= "#template_header { background-color: #231f20; }";
return $css;
}
@grayayer
grayayer / restrict.php
Last active October 5, 2016 17:55 — forked from mikeyarce/restrict.php
WooCommerce Memberships restriction on a page through using a template. This is how we can easily do it for pages that aren't generated through a post, like the Events Calendar archive
<?php
$user_id = get_current_user_id();
if ( wc_memberships_is_user_active_member( $user_id, 'gold' ) ) {
get_template_part( 'template', 'gold' );
} else {
echo "You are not allowed to view this content";
}
?>
@grayayer
grayayer / ce-redirect.php
Created September 29, 2016 17:31 — forked from jg314/ce-redirect.php
Events Calendar Community Events: Redirect users to a new page after submission
<?php
/*
* Send visitors who submit events to a different page after submission.
*
* This actually does the redirect. If an event was submitted, and we're about
* to reload the submission page (with a message instead of a form), this will
* redirect the user.
*
* @param WP $wp
* @return void
@grayayer
grayayer / add_helpful_user_classes.php
Last active April 22, 2017 01:23
Appends user role and id to the body classes for for front and backend in wordpress. Place this in a functionality plugin or functions.php file in the theme.
function add_helpful_user_classes() {
if ( is_user_logged_in() ) {
add_filter('body_class','class_to_body');
add_filter('admin_body_class', 'class_to_body_admin');
}
}
add_action('init', 'add_helpful_user_classes');
/// Add user role class to front-end body tag
function class_to_body($classes) {