WooCommerce Boilerplates and Snippets

Are you looking to start a WooCommerce store, but not sure where to begin? Or maybe you’ve already got a store up and running, but you’re not happy with the design or functionality. In either case, using a boilerplate template could be the solution you’re looking for.

Boilerplate templates are pre-made themes that give you a head start on your design and development process. They include everything from the basics like layout and styling, to more advanced features like integrations with payment processors and shipping services.

So, whether you’re just starting out or you want to take your WooCommerce store to the next level, here are some of the best boilerplate templates around.

Best WooCommerce Boilerplates

WooCommerce E2E Tests Boilerplate

If you’re looking for a simple and straightforward way to get started with E2E testing for your WooCommerce extension, this is the repo for you! With easy-to-follow set up instructions and a stripped down version of the default WooCommerce E2E test suite, it’s never been easier to set up rigorous quality assurance for your plugin.

WooCommerce Snippets

Remove “[Product] has been added to your cart” message

//remove
add_filter( 'wc_add_to_cart_message_html', '__return_null' );

//edit
add_filter( 'wc_add_to_cart_message_html', 'my_theme_custom_add_to_cart_message' );
function my_theme_custom_add_to_cart_message() {
   $message = 'Thank you for purchasing this product';
   return $message;
}

Add sort by featured

add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
  $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
	if ( 'featured' == $orderby_value ) {
		$args['orderby'] = '_featured';
		$args['order'] = 'asc';
		$args['meta_key'] = '';
	}
	return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
	$sortbyfeatureed['featured'] = 'Featured';
	$sortby = $sortbyfeatureed + $sortby;
	return $sortby;
}

Change Add to Cart button text

// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' ); 
function woocommerce_custom_single_add_to_cart_text() {
    return __( 'Add to Basket', 'woocommerce' ); 
}

// To change add to cart text on product archives page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );  
function woocommerce_custom_product_add_to_cart_text() {
    return __( 'Add to Basket', 'woocommerce' );
}

Modify breadcrumb

add_filter('woocommerce_breadcrumb_defaults', function( $defaults ) {
    unset($defaults['home']); //removes home link.    
    return $defaults;
});

Add product attributes to archive pages

add_action('woocommerce_after_shop_loop_item', 'my_theme_display_product_category', 10);
function my_theme_display_product_category(){
	global $product;
	if ( $product->has_attributes() ) {
		$colors = $product->get_attribute('pa_color');			
		echo $colors;
	}	
}

Check current page

//check out page
if(is_checkout()){ }
//cart page
if(is_cart()){ }
//store page
if(is_shop()){ }

Get Thumbnail Size

The size name of woocommerce image size is “woocommerce_thumbnail” and “shop_catalog”.

//list all size names
global $_wp_additional_image_sizes; 
var_dump( $_wp_additional_image_sizes ); 

Leave a Comment

Your email address will not be published. Required fields are marked *