Woocommerce Cheat Sheet

Add CSS only on the Shop page

change .xxx to the specific CSS element you want to change

.archive.post-type-archive-product.woocommerce .xxx {
background-color: pink;
}

Increase Your PHP Memory

Add this to wp-config.php

// Increase PHP Memory as recommended by Woocommerce
define( ‘WP_MEMORY_LIMIT’, ’64M’ );

Move WooCommerce Product Tabs under Product Summary

Add this to functions.php

// Remove tabs from the original location
remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_product_data_tabs’, 10 );

 

// Insert tabs under Product Summary
add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_output_product_data_tabs’, 60 );

Remove sidebar from Woocommerce

Remove this from wp-content/plugins/woocommerce/single-product.php

<?php
/**
* woocommerce_sidebar hook
* @hooked woocommerce_get_sidebar – 10
*/
do_action(‘woocommerce_sidebar’);
?>

Remove this from wp-content/plugins/woocommerce/archive-product.php

<?php
/**
* woocommerce_sidebar hook
* @hooked woocommerce_get_sidebar – 10
*/
do_action(‘woocommerce_sidebar’);
?>

Add this to style.css

#content-woocommerce {
width:100%;
}

Change the number of Woocommerce related products and columns
Add this to functions.php

<?php
/**
* Change number of related products on product page
* Set your own value for ‘posts_per_page’
*/
function woo_related_products_limit() {
global $product;

$args[‘posts_per_page’] = 6;
return $args;
}
add_filter( ‘woocommerce_output_related_products_args’, ‘jk_related_products_args’ );
function jk_related_products_args( $args ) {
$args[‘posts_per_page’] = 3; // 3 related products
$args[‘columns’] = 3; // arranged in 3 columns
return $args;
}

Remove Woocommerce checkout fields

// Woo remove checkout fields

add_filter( ‘woocommerce_checkout_fields’, ‘remove_woo_fields’, 9999 );
function remove_woo_fields( $woo_checkout_fields_array ) {
// leave these fields in checkout
// unset( $woo_checkout_fields_array[‘billing’][‘billing_first_name’] );
// unset( $woo_checkout_fields_array[‘billing’][‘billing_last_name’] );
// unset( $woo_checkout_fields_array[‘billing’][‘billing_address_1’] );
// unset( $woo_checkout_fields_array[‘billing’][‘billing_phone’] );
// unset( $woo_checkout_fields_array[‘billing’][‘billing_email’] );
// unset( $woo_checkout_fields_array[‘order’][‘order_comments’] ); // remove order notes
// unset( $woo_checkout_fields_array[‘billing’][‘billing_city’] );
// unset( $woo_checkout_fields_array[‘billing’][‘billing_state’] ); // remove state field
// unset( $woo_checkout_fields_array[‘billing’][‘billing_postcode’] ); // remove zip code field
// remove the billing fields below
unset( $woo_checkout_fields_array[‘billing’][‘billing_company’] ); // remove company field
unset( $woo_checkout_fields_array[‘billing’][‘billing_country’] );
unset( $woo_checkout_fields_array[‘billing’][‘billing_address_2’] );
return $woo_checkout_fields_array;
}

Require Woocommerce checkout fields

// Woo required checkout fields
add_filter(‘woocommerce_billing_fields’, ‘force_billing_fields’, 1000, 1);
function force_billing_fields($fields) {
  $fields[‘billing_first_name’][‘required’] = true;
  $fields[‘billing_last_name’][‘required’] = true;
  $fields[‘billing_address_1’][‘required’] = false;
  $fields[‘billing_city’][‘required’] = false;
  $fields[‘billing_postcode’][‘required’] = false;
  $fields[‘billing_country’][‘required’] = false;
  $fields[‘billing_state’][‘required’] = false;
  $fields[‘billing_email’][‘required’] = true;
  $fields[‘billing_phone’][‘required’] = true;
  return $fields;
}

 

Field names for Woocommerce checkout

billing_first_name
billing_last_name
billing_company
billing_country
billing_address_1
billing_address_2
billing_city
billing_state
billing_postcode
billing_phone
billing_email
Shipping Fields

shipping_first_name
shipping_last_name
shipping_company
shipping_country
shipping_address_1
shipping_address_2
shipping_city
shipping_state
shipping_postcode
Order Fields

order_comments