Working with WooCommerce

Once you have WordPress set up you can download the plugin from woocommerce. Once downloaded add the woocommerce file into your plugins folder in your local build then in your functions.php file add add_theme_support( 'woocommerce' );. Once this has been done activate the plugin on the admin page and refresh, you should now be able to access WooCommerce on the admin page to create products on the site.

Remember if you want to make any changes to the template code file to add a WooCommerce folder into your theme folder and keep the same structure of file the same as that of the template files. E.g. woocommerce/single-product/up-sells.php

Setting up products

You can add a new product to sell by going to the Products tab and Add New. Here you will be given the ability to name your product and give it a description. Underneath this will be the Product data section where you can define what type of product your are selling, most likely this will either be Simple or Variable.

Variable products

To create a variable product you will first need to add attributes in the Attributes tab, these can be dates, sizes or colours. The value of these must be separated by ‘|’ e.g. red | blue | green

Once you have added your variations remember to select the used for variations box. Go to the Variations tab and in the add variation box select create variations from all attributes then click go. This will populate the area below with all possible variations from the attributes.

This tab can also be used perform bulk operations for all of the variations for status, pricing, shipping and inventory. You can also expand each variation where you can the change values independently such as price, stock, SKU and the products image.


These can be used to separate products and products may have multiple categories to help control where they will appear on the shop. This is also in the Products tab.

Useful hooks

There are many useful hooks that you can use to make quick changes to the shop without having to deal with the PHP or HTML. These hooks can include renaming tabs, removing/editing buttons, reordering lines, hiding element or trim zeros.

renaming product tabs:

add_filter( 'woocommerce_product_tabs', 'wpb_rename_tabs',98);
function wpb_rename_tabs($tabs){
  $tabs['additional_information']['title'] = __( 'Details', 'text-domain' );
  $tabs['product_enquiry']['title'] = __( 'enquiry' );
  return $tabs;

removed the add to cart button on the category page:

add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );
function remove_add_to_cart_buttons() {
  if( is_product_category() || is_shop()) {
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );

reordering rating and price:

remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 13 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 11 );

removes select option button on category page:

add_filter( 'woocommerce_loop_add_to_cart_link', function( $product ) {
	global $product;
	if ( is_shop() && 'variable' === $product->product_type ) {
		return '';
	} else {
		sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
			esc_url( $product->add_to_cart_url() ),
			esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
			esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
			isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
			esc_html( $product->add_to_cart_text() )
} );

changes text of button on product page:

add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' );     // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' );  // 2.1 +
function woo_custom_single_add_to_cart_text() {
    return __( 'ADD TO BASKET', 'woocommerce' );

hides the sku element from the product page:

add_filter( 'wc_product_sku_enabled', '__return_false' );

Remove related products output:

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

removes category form single product:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

Trim zeros in price decimals:

 add_filter( 'woocommerce_price_trim_zeros', '__return_true' );