Skip to content

Instantly share code, notes, and snippets.

@nickburne
nickburne / Remove the ‘reviews’ tab so that only ‘product description’ appears
Created April 28, 2014 13:49
Remove the ‘reviews’ tab so that only ‘product description’ appears
.woocommerce .woocommerce-tabs ul.tabs {display:none !important}
@nickburne
nickburne / Customise the number of columns and products displayed per page
Created April 28, 2014 13:46
Customise the number of columns and products displayed per page
// Display 24 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );
@nickburne
nickburne / Change the number of related products displayed in your shop
Created April 28, 2014 13:44
Change the number of related products displayed in your shop
@nickburne
nickburne / Remove products from a particular category to show on the shop page
Created April 28, 2014 13:40
Remove products from a particular category to show 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() ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'PUT YOUR CATEGORY HERE' ), // Don't display products in the membership category on the shop page . For multiple category , separate it with comma.
'operator' => 'NOT IN'
@nickburne
nickburne / Remove product content based on the category
Created April 28, 2014 13:36
Remove product content based on the category
add_action( 'wp', 'remove_product_content' );
function remove_product_content() {
// If a product in the 'Cookware' category is being viewed...
if ( is_product() && has_term( 'Cookware', 'product_cat' ) ) {
//... Remove the images
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
// For a full list of what can be removed please see woocommerce-hooks.php
}
}
@nickburne
nickburne / Automatically add product to cart on visit
Created April 28, 2014 13:34
Automatically add product to cart on visit
* goes in theme functions.php or a custom plugin
// add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 64;
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
@nickburne
nickburne / Show the product description underneath an image
Created April 28, 2014 13:33
Show the product description underneath an image
add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5);
@nickburne
nickburne / Personalise a product tab to say exactly what you want
Created April 28, 2014 13:31
Personalise a product tab to say exactly what you want
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
@nickburne
nickburne / Remove specific (or all) of the product tabs
Created April 28, 2014 13:23
Remove specific (or all) of the product tabs
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
@nickburne
nickburne / Change the Woocommerce star ratings to show stars
Created April 28, 2014 13:21
Change the Woocommerce star ratings to show stars
.star-rating{float:right;width:80px;height:16px;background:url(images/star.png) repeat-x left 0}
.star-rating span{background:url(images/star.png) repeat-x left -32px;height:0;padding-top:16px;overflow:hidden;float:left}
.hreview-aggregate .star-rating{margin:10px 0 0 0}
#review_form #respond{position:static;margin:0;width:auto;padding:0 0 0;background:transparent none;border:0}
#review_form #respond:after{content:"";display:block;clear:both}
#review_form #respond p{margin:0 0 10px}
#review_form #respond .form-submit input{left:auto}
#review_form #respond textarea{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%}
p.stars:after{content:"";display:block;clear:both}
p.stars span{width:80px;height:16px;position:relative;float:left;background:url(images/star.png) repeat-x left 0}