Stock statuses can be important for your ecommerce stores for conveying stock related information to your customers. In some cases, it creates a sense of urgency which can result in increased sales & conversions.
WooCommerce’s default stock statuses are not customizable and you can not even add new stock statuses or edit existing statuses. Today we are going to discuss different ways in which you can add custom stock statuses in WooCommerce stores.
Ways to add Custom Stock Status in WooCommerce
There are two ways to add Custom Stock Status in WooCommerce. These ways are:
- Adding Custom Stock Status through plugin
- Adding Custom Stock Status programmatically
In this article, we have discussed the advantages and limitations of 2 possible ways of adding custom stock status in WooCommerce, here is a brief overview:
Comparison of Both Methods
Features | WooCommerce Custom Stock Status | Programing based solution |
Multiple Stock Statuses | Yes | No |
Quantity Based Stock Status | Yes | No |
Show custom stock status by user roles | Yes | No |
Easy to implement | Yes | No |
Customizable Stock Message | Yes | No |
Stock Status location change | Yes | No |
Stock Colour and Font Change | Yes | No |
Stock Status for Categories | Yes | No |
Stock Status for Product page | Yes | No |
Show Multiple Stock Status | Yes | No |
Image Stock Status | Yes | No |
Disable default stock status | Yes | No |
Out of stock message | Yes | Yes |
Custom Stock text | Yes | Yes |
Let’s discuss each method in detail.
Adding Stock Status with WooCommerce Custom Stock Status by Addify
The first method of adding custom stock status is by using the WooCommerce Custom Stock Status plugin by Addify. This method is by far the easiest method of implementing custom stock status in WooCommerce and the plugin gives you so many added features as well.
So let’s discuss how to add custom stock status in WooCommerce with this plugin by Addify.
Installation
- Download the .zip file from your WooCommerce account.
- From the WordPress Admin panel, go to Plugins > Add New and Upload Plugin. Choose the file you have downloaded.
- Install Now and Activate.
Adding Stock Status
Once you have activated the plugin it becomes usable and in order to add custom stock status go to WooCommerce Settings open Custom Stock Status. In custom stock status you have to select “Add New” for new stock status rule creation. Now this rule should be uniquely named so in case of multiple rule creation, it’s easy to find which rule does what. Once you have initiated the process of creating a new stock status rule now you can customise your stock status in following ways:
User Roles
For creation of Stock Status rule first you have to select for which user roles is the rule being created. In WooCommerce Custom Stock Status you get multiple user role options to choose from. These options are:
- Administrator
- Author
- Editor
- Contributor
- Subscriber
- Customer
- Shop Manager
- Guest
The new stock status will only be visible to the user roles you will select. Not selecting any user role will result in visibility of stock status for all visitors.
Apply to Products
After selecting the user role in Custom Stock Status for WooCommerce, the next option will be a checkbox if you select this checkbox then this single rule will apply to all the products and not selecting this option will result in 2 options:
- Select Products
- Select Categories
Select Products
In this option you will have to select products to apply the rule on. This section has predictive text enabled so typing 3 letters minimum will trigger the predictive text and you can select the desired product.
Select Product Categories
In this option you can select one or multiple categories to apply the rule on.
Application of sub-rules
Once you are done with all these steps then a new stock status rule will be created, the next step then is to apply the sub rules. Sub rules contain the following options:
Add Title
You can add a title for your sub rules because when multiple rules and multiple sub rules exist then it will become easier for future reference.
Order
In case of multiple sub rule creation select priority for the sub rules which one should be applied first
Out of stock
In WooCommerce Custom Stock Status sub rule creation you can check the out of stock box to create a custom out of stock message. Selecting this option will disable the stock range option because the message will automatically be displayed when the quantity reaches 0.
Message Type
The WooCommerce Custom Stock Status gives you four different options for displaying stock status messages. These 4 options are:
- Text Message – You can display the stock status with a custom text of your choice. Type a lucrative message to create a sense of urgency in your customers and don’t forget to add the {stock_qty} variable in order to show the stock quantity with the custom message. For example “Hurry up, only {stock_qty} pieces left‘
- Text Message with Icons – In addition to displaying text based stock messages you can also add relevant icons to the stock message to make it more appealing to the customers.
- Image – Instead of adding text messages just simply add an image of your choice for a stock message.
- Text Message with Date – You can also display date with an influential message. Add date in case of a special offer or restock date with a date picker.
Once you have completed the process then select rule priority and then select save and publish the stock status.
Other Features of WooCommerce Custom Stock Status
Now that we have discussed adding custom stock status in WooCommerce, let’s have a quick look at some value added features of WooCommerce Custom Stock Status.
- Stock Status Visibility – You can manage the visibility and location of stock status through this plugin. You have multiple options of pages to choose from for displaying stock status. These options are:
- Stock Status – Shop Page – Stock status can be displayed on the shop page and you get multiple location options on where to place the stock status on the shop page.
- Display Location – Shop Page – With this plugin you get multiple options to place stock status. These options are:
- Before Product Title
- After Product Title
- After Product Price
- After Add to Cart Button
- Stock Status – Product Page – If you select this option the stock status will be displayed on the product page.
- Display Location – Product Page – The custom stock status will be displayed on product page below price and above the add to cart button
- Disable Default Stock Status – With WooCommerce Custom Stock Status you can disable or enable the default stock status. However it must be noted that you only enable or disable the default stock status and not edit the default status’s settings. You can enable the display of default stock status to be displayed on the shop page or product page.
- Display Multiple Status – You get a multiple stock status checkbox and checking it will take you to the rule priority where if you have 2 stock statuses for the same product and same quantity range then which will be applied first.
- Stock Font and Stock Colour – WooCommerce Custom Stock Status also gives the option to change the stock status’ colour and font size.
Adding Custom Stock Status in WooCommerce Programatically
In order to add custom stock status programmatically you need to follow the following steps:
- Go to WooCommerce Settings
- Open child theme’s function.php file
- Paste this code in the file
function add_custom_stock_type() {
?>
<script type="text/javascript">
jQuery(function(){
jQuery('._stock_status_field').not('.custom-stock-status').remove();
});
</script>
<?php
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'Enter Text' => __( 'Enter Text', 'woocommerce' ),
'Enter Text' => __( 'Enter Text', 'woocommerce' ),
'Enter Text' => __( 'Enter Text', 'woocommerce' ),
'Enter Text' => __( 'Enter Text', 'woocommerce' ),
), 'desc_tip' => true, 'description' => __( 'Assign the stock status text to be listed on the front end.', 'woocommerce' ) ) );
}
add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');
function save_custom_stock_status( $product_id ) {
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
}
add_action('woocommerce_process_product_meta', 'save_custom_stock_status',99,1);
function woo_add_custom_general_fields_save_two( $post_id ){
// Select
$woocommerce_select = $_POST['_stock_status'];
if( !empty( $woocommerce_select ) )
update_post_meta( $post_id, '_stock_status', esc_attr( $woocommerce_select ) );
else
update_post_meta( $post_id, '_stock_status', '' );
}
function woocommerce_get_custom_availability( $data, $product ) {
switch( $product->stock_status ) {
case 'readytoship':
$data = array( 'availability' => __( 'ENTER STOCK STATUS TEXT', 'woocommerce' ), 'class' => 'ready-to-ship' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'ENTER STOCK STATUS TEXT', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
case 'onbackorder':
$data = array( 'availability' => __( 'ENTER STOCK STATUS TEXT', 'woocommerce' ), 'class' => 'onbackorder' );
break;
case 'customized':
$data = array( 'availability' => __( 'ENTER STOCK STATUS TEXT', 'woocommerce' ), 'class' => 'customized' ); //added new one
break;
}
return $data;
}
add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 10, 2);
Once you have pasted the code there are a few edits in the code that are required. The first one is to assign the stock statuses of your choice to replace the existing stock statuses i.e “Back in stock” instead of “Available”. The second edit required is to add these terms to stock status dropdown and for that you need to enter the terms you assigned to existing stock statuses in front of ‘availability’
Once you are done with the edits then save the file and see if the changes are applied. You should see the added stock statuses in the stock status dropdown now.
Limitations
Adding stock statuses programmatically have some limitations. These limitations are:
- You can only modify the stock statuses in text format and can’t add images as stock status
- You can not add quantity based stock statuses i.e 5 pieces left only
- You can not hide/display custom stock statuses by user roles
- Complex programming knowledge required in order to perform the task
Conclusion
Adding custom stock status programmatically is harder and has some limitations. While on the other hand WooCommerce Custom Stock Status is a feature-rich plugin that delivers more than expected and is very easy to install and use as well.