Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / Remove duplicate stars on your product
Created April 29, 2014 10:56
Remove duplicate stars on your product
.star-rating span:before, ul.products li.product .product-details .star-rating:before {
content:none;
}
@nickburne
nickburne / Automatically complete orders in WooCommerce
Created April 30, 2014 14:23
Automatically complete orders in WooCommerce
/**
* Auto Complete all WooCommerce orders.
* Add to theme functions.php file
*/
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
global $woocommerce;
if ( !$order_id )
@nickburne
nickburne / Alter the default state and country at the checkout
Created April 30, 2014 14:27
Alter the default state and country at the checkout
/**
* Manipulate default state and countries
*
* As always, code goes in your theme functions.php file
*/
add_filter( 'default_checkout_country', 'change_default_checkout_country' );
add_filter( 'default_checkout_state', 'change_default_checkout_state' );
function change_default_checkout_country() {
return 'XX'; // country code
}
@nickburne
nickburne / Automatically mark orders as ‘complete’ in WooCommerce
Created April 30, 2014 14:29
Automatically mark orders as ‘complete’ in WooCommerce
add_filter( 'woocommerce_payment_complete_order_status', 'virtual_order_payment_complete_order_status', 10, 2 );
function virtual_order_payment_complete_order_status( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
if ( 'processing' == $order_status &&
( 'on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status ) ) {
$virtual_order = null;
if ( count( $order->get_items() ) > 0 ) {
foreach( $order->get_items() as $item ) {
if ( 'line_item' == $item['type'] ) {
$_product = $order->get_product_from_item( $item );
@nickburne
nickburne / Add a checkbox field to checkout with a simple snippet in WooCommerce
Created April 30, 2014 14:32
Add a checkbox field to checkout with a simple snippet in WooCommerce
<?php
/**
* Add checkbox field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my-new-field"><h3>'.__('My Checkbox: ').'</h3>';
woocommerce_form_field( 'my_checkbox', array(
'type' => 'checkbox',
'class' => array('input-checkbox'),