Skip to content

Instantly share code, notes, and snippets.

View wbcomdev's full-sized avatar

Wbcom Dev wbcomdev

View GitHub Profile
// 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>
<?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 } ?>
<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();
/**
* 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' );
}
}
/**
* 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;
}
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
/**
* 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 );
/**
* 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 );
/**
* Change number of products that are displayed per page (shop page).
*/
function wb_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;
}
add_filter( 'loop_shop_per_page', 'wb_loop_shop_per_page', 20 );
/**
* Set a minimum order amount for checkout.
*/
function wb_wc_minimum_order_amount() {
// Set this variable to specify a minimum order value.
$minimum = 50;
if ( WC()->cart->total < $minimum ) {
if ( is_cart() ) {