Skip to content

Instantly share code, notes, and snippets.

View wbcomdev's full-sized avatar

Wbcom Dev wbcomdev

View GitHub Profile
/**
* Change number or products per row to 3.
*/
if ( ! function_exists( 'loop_columns' ) ) {
function wb_loop_columns() {
return 3; // 3 products per row
}
}
add_filter( 'loop_shop_columns', 'wb_loop_columns', 999 );
/**
* Override theme default specification for product # per row.
*/
function wb_loop_columns() {
return 5; // 5 products per row.
}
add_filter( 'loop_shop_columns', 'wb_loop_columns', 999 );
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
/**
* Set WooCommerce image dimensions upon theme activation.
*/
function wb_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss.
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout.
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation.
return $enqueue_styles;
}
/**
* Enqueue your own stylesheet.
*/
function wb_enqueue_woocommerce_style() {
wp_register_style( 'mytheme-woocommerce', get_template_directory_uri() . '/css/woocommerce.css' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'mytheme-woocommerce' );
}
}
<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();
<?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 } ?>
// Use in conjunction with https://gist.github.com/wbcomdev/d85be8c3dc7dbf42f7c19b6e888d3c05
<a class="cart-customlocation" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
/**
* Show cart contents / total Ajax.
*/
function wb_woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-customlocation" href="<?php echo esc_url( wc_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>
if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {
/**
* Hide loop read more buttons for out of stock items.
*/
function woocommerce_template_loop_add_to_cart() {
global $product;
if ( ! $product->is_in_stock() || ! $product->is_purchasable() ) {
return;
}
wc_get_template( 'loop/add-to-cart.php' );