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
Last active January 19, 2016 14:34
WooCommerce - Disable default stylesheet
define( 'WOOCOMMERCE_USE_CSS', false );
@jameskoster
jameskoster / functions.php
Created January 12, 2012 16:58
WooCommerce - Change number of products per row
// Change number or products per row to 3
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 3; // 3 products per row
}
}
@jameskoster
jameskoster / functions.php
Last active November 21, 2023 11:32
WooCommerce - change number of products displayed per page
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 9;
return $cols;
}
@jameskoster
jameskoster / grid.css
Created January 16, 2012 22:29
% flexible 12 col grid
.onecol, .twocol, .threecol, .fourcol, .fivecol, .sixcol, .sevencol, .eightcol, .ninecol, .tencol, .elevencol {
margin-right:3.8%;
}
.onecol {
width: 4.85%;
}
.twocol {
width: 13.45%;
@jameskoster
jameskoster / functions.php
Last active July 3, 2018 14:19
WooCommerce - set image dimensions upon theme activation
<?php
/**
* Hook in on activation
*/
/**
* Define image sizes
*/
function yourtheme_woocommerce_image_dimensions() {
global $pagenow;
@jameskoster
jameskoster / index.php
Last active March 12, 2017 06:30
WooCommerce - Sample products loop
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 12
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
@jameskoster
jameskoster / functions.php
Created January 30, 2012 15:37
WooCommece - Exclude a category from shop page
<?php
/**
* This code should be added to functions.php of your theme
**/
add_filter( 'parse_query', 'custom_parse_query' );
function custom_parse_query( $q ) {
if ( !$q->is_post_type_archive() ) return;
@jameskoster
jameskoster / header.php
Last active January 19, 2017 10:42
WooCommerce - Checkout link (when cart is not empty)
global $woocommerce;
if ( sizeof( $woocommerce->cart->cart_contents) > 0 ) :
echo '<a href="' . $woocommerce->cart->get_checkout_url() . '" title="' . __( 'Checkout' ) . '">' . __( 'Checkout' ) . '</a>';
endif;
@jameskoster
jameskoster / header.php
Created February 3, 2012 12:47
WooCommerce - My Account link
<?php if ( is_user_logged_in() ) { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
<?php }
else { ?>
<a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?></a>
<?php } ?>
@jameskoster
jameskoster / header.php
Created February 3, 2012 12:57
WooCommerce - show cart contents/total
<?php global $woocommerce; ?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();