Skip to content

Instantly share code, notes, and snippets.

View jameskoster's full-sized avatar
🍕

James Koster jameskoster

🍕
View GitHub Profile
@jameskoster
jameskoster / functions.php
Created February 12, 2012 23:19
WooCommerce - Change number of upsells displayed and # of products per row
remove_action( 'woocommerce_after_single_product', 'woocommerce_upsell_display');
add_action( 'woocommerce_after_single_product', 'woocommerce_output_upsells', 20);
if (!function_exists('woocommerce_output_upsells')) {
function woocommerce_output_upsells() {
woocommerce_upsell_display(3,3); // Display 3 products in rows of 3
}
}
@jameskoster
jameskoster / functions.php
Last active September 30, 2015 19:48
WooCommerce - Allow shortcodes in product excerpts
if (!function_exists('woocommerce_template_single_excerpt')) {
function woocommerce_template_single_excerpt( $post ) {
global $post;
if ($post->post_excerpt) echo '<div itemprop="description">' . do_shortcode(wpautop(wptexturize($post->post_excerpt))) . '</div>';
}
}
@jameskoster
jameskoster / functions.php
Created June 6, 2012 10:35
WooCommerce - Change number of thumbnails per row in product galleries
add_filter ( 'woocommerce_product_thumbnails_columns', 'xx_thumb_cols' );
function xx_thumb_cols() {
return 4; // .last class applied to every 4th thumbnail
}
@jameskoster
jameskoster / script.js
Last active October 7, 2015 12:28
Add a .parent class to parent menu items in wp_nav_menu
jQuery(document).ready(function() {
jQuery( 'ul.sub-menu' ).parent().addClass( 'parent' );
}
@jameskoster
jameskoster / gist:4038260
Created November 8, 2012 11:25
WooCommerce 'out of stock' on product archives
// The following goes in functions.php
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_stock', 10);
function woocommerce_template_loop_stock() {
global $product;
if ( ! $product->managing_stock() && ! $product->is_in_stock() )
echo '<p class="stock out-of-stock">out-of-stock</p>';
}
@jameskoster
jameskoster / functions.php
Last active August 31, 2021 14:18 — forked from mikejolley/functions.php
WooCommerce - Exclude products from a particular category on the shop page
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$q->set( 'tax_query', array(array(
@jameskoster
jameskoster / functions.php
Last active June 18, 2017 19:20
Change number of products per row in a WooThemes WooCommerce theme
// Override theme default specification for product # per row
function loop_columns() {
return 5; // 5 products per row
}
add_filter('loop_shop_columns', 'loop_columns', 999);
@jameskoster
jameskoster / functions.php
Created January 10, 2013 14:03
WooCommerce - display rating aggregate in product loop
add_action( 'woocommerce_after_shop_loop_item', 'wc_product_rating_overview', 15 );
if ( ! function_exists( 'wc_product_rating_overview' ) ) {
function wc_product_rating_overview() {
global $product;
echo $product->get_rating_html();
}
}
@jameskoster
jameskoster / functions.php
Created January 12, 2013 16:01
WooCommerce - hide ratings on product loop
// Remove the product rating display on product loops
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
@jameskoster
jameskoster / functions.php
Last active December 11, 2015 20:59
WooCommerce - enqueue your own stylesheet
function wp_enqueue_woocommerce_style(){
wp_register_style( 'mytheme-woocommerce', get_template_directory_uri() . '/css/woocommerce.css' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'mytheme-woocommerce' );
}
}
add_action( 'wp_enqueue_scripts', 'wp_enqueue_woocommerce_style' );