Ultimate guide: Best WooCommerce Snippets to Tailor Your Online Shop – Best of 2023

Best WooCommerce Snippets to Tailor Your Online Shop
Best WooCommerce Snippets to Tailor Your Online Shop

Are looking for the best WooCommerce Snippets to Tailor Your Online Shop? Over the previous some years, WooCommerce is a powerful WordPress e-commerce plugin. It has some good reasons that are why it’s always on the top.

As WooCommerce is widely popular e-commerce platform, it lets you create an e-commerce business (store), manage inventory, accept payments, and much more. It comes with almost all the functionalities that you require to open an online store. And, It helps you sell products or services online from your WordPress site at a very affordable and accessible manner. 

Designed by WooThemes, WooCommerce is flexible enough to give your customers a pleasant online shopping experience. Looking at its adaptive nature, online players are seeing this plugin as a means of expanding their business quickly and easily.

Plugin is defined as a type of software that contains a group of functions that can be added to a WordPress website. They are used to provide additional functionality to your application.

WooCommerce claims enough settings and great support. However, while personalizing your store, you may need to zoom in some functionality, which will call for the use of the code. Today, In this post, We have compiled a list of 10 WooCommerce code snippets that can be useful to meet many tasks like online retailers like you, possibly in a highly feasible way.

WooCommerce Snippets

Code snippets just provide some high level of optimization that allows you to meet your needs which is really infinite. Also, the code snippets plugin allows you to easily create and apply any number of PHP snippets using the familiar system, similar to the plugins page. When using this WordPress plugin to add custom code, you are able to keep track of your code snippets.

So, let’s take a look!

Read More: Ultimate Guide: How to Display Code Snippets in WordPress Post

1. Add a Message to the Login/Registration Form

Those who want to add any message at the top of the login area or registration form, simply use the snippet as shown below:

function wdm_login_message() {

   if ( get_option( ‘woocommerce_enable_myaccount_registration’ ) == ‘yes’ ) {


       <div class=”woocommerce-info”>

       <p><?php _e( ‘Your custom message goes here.’ ); ?></p>





add_action( ‘woocommerce_before_customer_login_form’, ‘wdm_login_message’ );

2. Customizing the WooCommerce Breadcrumb

Breadcrumb may be a great solution for several sites, to reduce user navigation and simply search engine optimization. As the search engine is a service which allows all internet user to search for any content, query, and product throughout the world wide web. 

Where, Breadcrumb in WordPress is a feature that helps users to navigate your site. Breadcrumb creates links that connect back with the homepage and the current page. It is linked thread between the current page and home page.

WordPress breadcrumb navigation helps users to understand which location they are on a site. Apart from that, it can also help Google to understand the relevance of your site to a specific keyword.

But how can this be done if you want to change the default text of an item?

add_filter( ‘woocommerce_breadcrumb_defaults’, ‘wdm_change_breadcrumb_home_text’ );

function wdm_change_breadcrumb_home_text( $defaults ) {

   // change the breadcrumb home text from ‘Home’ to ‘Store’

   $defaults[‘home’] = ‘Store’;

   return $defaults;


To change the breadcrumb separator, use the following code.

add_filter( ‘woocommerce_breadcrumb_defaults’, ‘wdm_change_breadcrumb_separator’ );

function wdm_change_breadcrumb_separator( $defaults ) {

   // change the breadcrumb delimiter from ‘/’ to ‘>’

   $defaults[‘delimiter’] = ‘ &gt; ‘;

   return $defaults;


3. Remove Specific Product Tabs

To remove a specific product tab, like as ‘product description’, or ‘review’, use the code of code given below.

add_filter( ‘woocommerce_product_tabs’, ‘wdm_remove_product_tabs’, 99 );

function wdm_remove_product_tabs( $tabs ) {

   // remove the description tab

   unset( $tabs[‘description’] );

   // remove the reviews tab

   unset( $tabs[‘reviews’] );

   // remove the additional information tab

   unset( $tabs[‘additional_information’] );

   return $tabs;


4. Redirect to Checkout page after Add to Cart

When your products are such that customers buy the only single product at a time, you can redirect directly to ‘Add to Cart’ on the checkout page.

function wdm_add_to_cart_checkout_redirect() {

   wp_safe_redirect( get_permalink( get_option( ‘woocommerce_checkout_page_id’ ) ) );



add_action( ‘woocommerce_add_to_cart’,  ‘wdm_add_to_cart_checkout_redirect’, 11 );

6. Add Payment type to the Admin Email

The code snippet shown below will help you remove products from a specific category from your store page.

function wdm_remove_product_categories( $q ) {

   if ( ! $q->is_main_query() ) return;

   if ( ! $q->is_post_type_archive() ) return;

   if ( ! is_admin() && is_shop() && ! is_user_logged_in() ) {

       $q->set( ‘tax_query’, array(array(

            ‘taxonomy’ => ‘product_cat’,

            ‘field’ => ‘slug’,

            // don’t display products from these categories on the shop page

           ‘terms’ => array( ‘red’, ‘old’ ),

           ‘operator’ => ‘NOT IN’



   // once it’s done, unhook

   remove_action( ‘pre_get_posts’, ‘wdm_remove_product_categories’ );


add_action( ‘pre_get_posts’, ‘wdm_remove_product_categories’ );

7. Automatically Change the Order Status

If you prefer to use the manual gateway for payment, and you want to mark these orders as ‘complete’, then you only need the following code snippets.

// automatically update the order status to ‘Complete’

function wdm_auto_complete_on_hold_order( $order_id ) {

   $order = new WC_Order( $order_id );

   if ( ‘on-hold’ === $order->status )

       $order->update_status( ‘completed’ );


add_action( ‘woocommerce_thankyou’, ‘wdm_auto_complete_on_hold_order’ );

8. Hide Flat Rate Shipping if Free Shipping is Available

Use the following code snippet to hide some shipping methods like ‘flat rate’ shipping.

//hide the flat rate shipping option when free shipping is available

add_filter( ‘woocommerce_available_shipping_methods’, ‘hide_standard_shipping_when_free_is_available’ , 10, 1 );

function hide_standard_shipping_when_free_is_available( $available_methods ) {

   if( isset( $available_methods[‘free_shipping’] ) AND isset( $available_methods[‘flat_rate’] ) ) {

       // remove standard shipping option

       unset( $available_methods[‘flat_rate’] );


   return $available_methods;


Use the code shown below, to hide all other shipping methods when free shipping is available.

add_filter( ‘woocommerce_package_rates’, ‘wdm_hide_shipping_when_free_is_available’, 10, 2 );

function wdm_hide_shipping_when_free_is_available( $rates, $package ) {

   // only modify rates if free_shipping is present

   if ( isset( $rates[‘free_shipping’] ) ) {

       // unset all methods except for free_shipping

       $free_shipping = $rates[‘free_shipping’];

       $rates = array();

       $rates[‘free_shipping’] = $free_shipping;


   return $rates;


9. Change the Currency from ‘$’ to ‘USD’

Want to display currency symbol differently? Use the following code:

// change the currency symbol

add_filter(‘woocommerce_currency_symbol’, ‘change_existing_currency_symbol’, 10, 2);

function change_existing_currency_symbol( $currency_symbol, $currency ) {

   switch( $currency ) {

       case ‘USD’: $currency_symbol = ‘USD’; break;


   return $currency_symbol;


10. Exclude a Category from the WooCommerce Category Widget

Sometimes, many categories can disorder the category widget. Widgets allows you to add content and features to your sidebar without writing any code. For example, there are some default widgets that come with WordPress such as Categories, Tag cloud, Search, etc. And there are a lot of WordPress plugins which can add their own widget.

In this situation, you want to remove specific categories from the widget and can only show certain people the code below will help you do this.

add_filter( ‘woocommerce_product_categories_widget_args’, ‘wdm_edit_product_cat_widget_args’ );

function wdm_edit_product_cat_widget_args( $cat_args ) {

   // remove specific categories using their id

   $cat_args[‘exclude’] = array(’16’);

   return $cat_args;


Wrapping Up

Here, in this, we have discussed 10 Resourceful WooCommerce Snippets for your online store.

Now, all of these are useful WooCommerce snippets for shaping your online store in very useful ways! So bookmark this post and start using them to easily customize your WooCommerce storeIf you facing any hurdle, let me know in the comments.

WordPress Support WPGlobalSupport
WordPress Technical Support – wpglobalsupport

If you’re looking for someone who can help you with WooCommerce then you can dial our WordPress technical support number +1-888-738-0846. We will be glad to help you.

Some of Our Popular Blogs:

Complete Guide: How to easily Hide WooCommerce Coupon Fields? Best of 2021

Complete Guide: How to accept multiple currencies in WooCommerce? Best of 2020

Leave a Reply