How to change WooCommerce Cart Items Counts?

Some businesses require to count the number of distinct items in the Cart, not the total items count. So, if there are Three “OAT DRINK“, two “OAT DRINK CHOCOLATE”, and One “OAT DRINK BARISTA EDITION” then we’ll show Three instead of Six.

How to change WooCommerce Cart Items Counts?

PHP Snippet: Custom Cart Item Count @ WooCommerce Mini Cart Header Widget

Where to add this snippet?

You can put this snippet at the bottom of your child theme functions.php file.

How to Add Custom Sorting Options for WooCommerce Shop

By default, WooCommerce has some basic sorting options on the shop page that works very well. However, you may want to have some extra sorting options for your WooCommerce store, so customers can easily find specific products they want.

Today, we will show you how to extend WooCommerce default sorting options on the shop page and add your custom sorting options.

Custom Sorting Options

WooCommerce has the following default sorting options:

  • Default sorting
  • Sort by popularity
  • Sort by average rating
  • Sort by latest
  • Sort by price: low to high
  • Sort by price: high to low

We will add the following custom sorting options:

  • Sort by popularity: last 30 days
  • Sort by popularity: last 60 days

WooCommerce already has a sorting option to sort products by popularity which display popular products by all time. But having extra two sorting options to find popular products, you are giving your customers more flexibility to find popular products for a specific time.

Prepare the Plugin

First, we will create a custom extension plugin for WooCommerce to write our custom PHP code. It’s easy to create a simple starter plugin using the WP CLI command.

Run the following command to generate a plugin with starter code:

Make sure to run the command from the installation of the WordPress root directory.

After the plugin is generated, open the wc-sorting-options.php file and update the header comment to the following:

Finally, the Sorting Options for WooCommerce plugin is ready to be activated from the WordPress admin dashboard.

Navigate to Plugins -> Installed Plugins and activate the plugin.

Don’t be panic, our plugin does not add any features yet. We will add custom features soon.

The Main Plugin Class

Let’s create our main plugin class where we will write most of our code to add custom sorting options.

Now include this class in our main plugin file with the following code:

Check for Woocommerce and Initialize the Plugin

To initialize the main plugin class you can write the following code in the main plugin file:

You have noticed that we are initializing the class only if the WooCommerce class exists. This ensures that the WooCommerce plugin is installed and activated before initializing our plugin class.

Update Product Sorting Options

Now, it’s time to update product sorting options. We will use woocommerce_catalog_orderby hook to add our custom sorting options by filtering the default options.

Update the main plugin class with the following code:

If you visit the shop page now, you will be able to see that new options are added to the select dropdown. However, these custom options do not work yet.

Filter the Query

In this step, we will filter the query clauses based on the selected sorting option. Update the main with the following code:

Now, add the missing callback function:

If you take a closer look into the above code, you will see that first, we are preparing the before and after dates. To filter products based on quantity and the specific date range we are using wc_order_product_lookup table which stores additional data for WC orders.

We are using product_qty column to get the sum of product quantity of order and date_created column to filter orders of specific date range. We are using a subquery to prepare items_sold for our main query.

Finally, if you go to the shop page and try to sort products by Sort by popularity: last 30 days or Sort by popularity: last 60 days you will get popular products based on your selected option.

It’s not just an end, you can more custom sorting options for your WooCommerce store by following the above instructions.

How to display “Out of Stock” Products Last in the Shop page (PLP) in WooCommerce?

One of the challenging parts  while running an online and a physical store, or multiple physical stores, is managing stock availability and inventory. You have to keep track of products that customers are interested in. You need to analyze buying behavior, predict consumer demand, and decide on stocking options. 

In our Product Listing Page (PLP), we generally show all the products by different orders. We also display the products that are out of stock. WooCommerce by default gives us some sorting option like sort by rating, sort by price, sort by popularity etc.

So if some products are out of stock still it would be in the beginning, which can lead to bad user experience. We should display in the end. We can do it in two different way.

  • Sort everything by _stock_status & ignore other filtering options.
  • Keep out of stock elements in the end & keep the filtering option intact
Sort every items by stock status (hide filtering option)

First we’ll remove the Default Sorting Dropdown.

// Remove “Default Sorting” Dropdown @ WooCommerce Shop & Archive Pages
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
// Remove “Default Sorting” Dropdown in StoreFront theme
add_action( 'wp', 'wpdrift_remove_default_sorting_storefront' );
function wpdrift_remove_default_sorting_storefront() {
   remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
   remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );

Now we need to use woocommerce_get_catalog_ordering_args hook to sort products by “stock_status” in “ASC” (ascending) order. Possible values are “instock”, “onbackorder”, “outofstock” so it will automatically display them alphabetically like this: instock, onbackorder, outofstock.

add_filter( 'woocommerce_get_catalog_ordering_args', 'wpdrift_first_sort_by_stock_count', 9999 );

//Sort Products By Stock Status
function wpdrift_first_sort_by_stock_count( $args ) {
   $args['orderby'] = 'meta_value';
   $args['order'] = 'ASC';
   $args['meta_key'] = '_stock_status';
   return $args;
Keep out of stock elements in the end & keep the filtering option intact

In the previous way, we have some issues. Though we are achieving the result we wanted but we had to remove the sorting option. Now we’ll try to achieve the result without removing the sorting option. We are using woocommerce_get_catalog_ordering_args & posts_clauses hooks to achieve the result.

add_filter( 'woocommerce_get_catalog_ordering_args', 'wpdrift_catalog_ordering_args' );
function wpdrift_catalog_ordering_args( $args ) {
	add_filter( 'posts_clauses', 'wpdrift_filter_posts_clauses', 9999 );
	return $args;
function wpdrift_filter_posts_clauses( $args ) {
	global $wpdb;
	if ( ! strstr( $args['join'], 'wc_product_meta_lookup' ) ) {
		$args['join'] .= " LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON $wpdb->posts.ID = wc_product_meta_lookup.product_id ";
	$args['orderby'] = 'wc_product_meta_lookup.stock_status ASC, ' . $args['orderby'];
	return $args;

PS: All your products must be using the “Managing Stock” option in the product edit page > Product Data > Inventory.

How to Start Selling Pizza Online using WooCommerce

If you are running a pizza delivery business or restaurant and want to get more sales by selling Pizza online, you will need a platform or system where you can automate everything. From online ordering to delivery it’s possible to manage everything from your own website. 

But when selling Pizza online you have to give customers flexibility to choose different options and build their desired Pizza before they place an order.

In this article, we will guide you about how you can turn your website into a Pizza delivery system and start selling Pizza online using WooCommerce.

Before We Get Started

Before we get started make sure you are running a website using WordPress. 

WordPress is open source software you can use to create a beautiful website, blog, or app.

Of course you can build a Pizza delivery system using WordPress. If your website is not powered by WordPress, you can learn more about it from their official website. You also can check the installation guide to set up a new website in minutes.

WordPress doesn’t provide features to turn your website into an eCommerce platform by default, but WooCommerce plugin can help you set up a new store in minutes.

WooCommerce is a customizable, open-source eCommerce platform built on WordPress. Get started quickly and make your way. 

You can quickly install and set up the WooCommerce plugin from the WordPress admin panel. You can check their installation guide to install, active and complete step by step Setup Wizard to make your website ready to start selling.

Install WPDrift for WooCommerce Plugin

WooCommerce helps you to sell Simple, Grouped, External and Variable products, but when selling Pizza online you need to give customers the ability to choose Pizza Size, Crust and Toppings. That’s why we need a WooCommerce extension which will help us to set up a Composite product with different components (Size, Crust and Toppings). 

By creating a Composite product we can give customers the power to build their own Pizza before they order it online.

You can learn more about WPDrift for WooCommerce plugin and download it from our official website.

Create A Composite Product (Pizza Builder)

When plugins are installed and setup is complete, we are ready to create a Composite product. It’s really easy to create WooCommerce products,  similar to writing a post in WordPress.

  • Go to WooCommerce > Products > Add Product. You then have a familiar interface and should immediately feel at home. 
  • Enter a product Title and Description
  • Go to the Product Data panel, and select Composite.

Add Components

Now it’s time to add components for Pizza Size, Crust and Toppings. First, click on the Components tab from the Product Data meta box.

On the Components tab, you will find 3 settings to configure before adding new components.

Layout Options

It allows you to choose how the components will be laid out on the product page. There are two layout options available.

  • Stacked – Components are stacked. 
  • Stacked with featured image  – Components are stacked on the right with featured images on the left.

Form Location

There are two options available.

By default components will be placed at the top with featured image and summary on the left.

If you choose After Summary, components will be displayed after the product summary.

Catalog Price

The following options are available for Catalog Price. 

  • Use defaults – Displays the price of the default configuration. Requires Default Option to be set in all non-optional Components.
  • Calculate from/to – Builds a price string based on the configuration with the lowest/highest price.
  • Hide – Hides the catalog price.

Add Component for Pizza Size

Before creating Component for Pizza size, we have to create 3 simple products: Personal, Medium and Family for this component’s options.

  • Go to WooCommerce > Products > Add Product
  • Enter a product Title and Description
  • Choose Simple Product as Product Type.
  • Enter Regular price, and click Publish button to make it live.

Similarly create two more products, so we can choose Personal, Medium and Family for this component’s options.

Now, to create our first Component to choose Pizza size, click on the Add component button.

Add Component Name and Description in the input fields. 

For the Component Options, you can either select Categories or Products. We will select three products: Personal, Medium and Family for product sizes.

We will select List for Options Style and not check the Multiple checkbox, so customers can select only one size.

We will check Priced Individually checkbox and keep all remaining settings unchanged and move forward to add next components.

Add Component to Choose Pizza Crust

Next component is Pizza Crust, we will give customers to choose from two different options. 

First, create four simple products Thin Crust, Golden Surprise, Cheesy Bites and Pan Pizza for this component’s options.

When creating these products save under Crust List category.

Now, let’s add a new component, select Crust List category as Component Options, and List as Options Style.

We will check Priced Individually checkbox and keep all other settings unchanged and move to the next step.

Add Component for Pizza Toppings

Pizza Toppings are the most important ingredients  and customers need the flexibility to choose multiple ingredients easily.

First, create several simple products for this component’s options. When creating these products save under Toppings List category.

Now, for the Component Options, we will select the Toppings List category where we have added our all topping products.

Select List as Options Style and check Multiple checkbox to give customers ability to choose multiple toppings.

We will check Priced Individually checkbox and keep all remaining settings unchanged and move forward to add next components.

Publish Your Pizza Builder

When everything is done, we can publish our Composite Product (Pizza Builder) and make it live for the customers.

The Composite Product will look like the following on single product page.

On the directory page, when you click on the Add to cart button, a popup will be displayed on like the following.

Enjoy! 🎉

WooCommerce 4.0 comes with new admin interface with a updated Onboarding Experience

Automatic has released version 4.0 of its WooCommerce module. With the exception of the latest admin gui, which has been in production for over a year, the development of this upgrade started in January 2020. The upgrade also provides an improved on-board interface for mobile customers.

Version 4.0 is the latest version of the addon. Users will render a copy of the servers before updating. The WooCommerce team recommends checking on a staging platform before switching to a live server to insure that it operates smoothly.

The latest edition is not completely backward compatible with the prior versions of WooCommerce. Reading the guide How to upgrade WooCommerce before pressing the update button is suggested.

Developers and end-users will take care of improvements to the Action Scheduler Repository, which is a background task runner in WooCommerce. In the past, data was stored as a custom post sort, but has now been moved to a custom database table.

The move will allow background operations more effective with a huge volume of data. This still has the ability to disable custom code that does not explicitly communicate with the API, although that would not be a concern for most users.

What’s new in 4.0?

4.0 is the first big update of 2020 and we are looking forward to having a new edition of WooCommerce Admin with this series. WooCommerce Admin is the first step toward a more streamlined WooCommerce core JavaScript-driven interface.

WooCommerce Admin


  1. New dashboard
  2. New and improved reports
  3. Improved notification experience
  4. New store management tools

WooCommerce admin has far greater monitoring features than prior versions of reports and allows analysis, contrasts and overviews of how the shop performs in terms of transactions, earnings, which are the most popular / highest-grossing items, introduces tools for increased consumer retention and analytics.

We have made it very simple to export data from files as a csv to allow for seamless integration with other systems.

Together with the admin of WooCommerce, we are introducing to all customers a modern Company Panel with better order processing functionality and continuity between web and smartphone interface.

According to the JavaScript specifications, this interface must be rendered accessible to all shops operating WordPress 5.3+. The shop that uses older versions of WordPress would also have WooCommerce Admin removed.

Action Scheduler 3.1

One of the fundamental technology that has allowed WooCommerce Admin is Action Scheduler— a background task runner already used in the WooCommerce heart. The 3.1 edition that we’re using in WooCommerce 4.0 is a fresh, more efficient edition of Action Scheduler that uses custom tables to offer better functionality including in stores with huge amounts of orders and posts in the database.

New Onboarding Experience

Starting a shop can be a challenging and frustrating process, so we trust that we can help our new customers get their shop up and running quicker and more quickly. As a consequence, 50% of our potential clients will be willing to seek out a fresh on-board experience.

Upgrading to 4.0

WooCommerce 4.0 is a new big update, which indicates that it is not completely backward compatible with previous versions of WooCommerce. However, the update we are making is just at the stage of the Action Scheduler framework and thus the improvement is intended to function well for most customers. We recommend testing and backing up prior to upgrading and following our upgrade guide.

There are a few post-update database maintenance procedures that need to be performed after upgrading. For very wide tables, we suggest performing the installation process using the WP CLI command wp wc update instead of utilizing the admin gui.

When you are a developer and have skipped the trial and release candidate (RC), the following details could be useful:

Deprecated Functions and Methods

  • countries_using_vat got replaced by WC_Countries::get_vat_countries

Template File Changes in 4.0

The following template files have been updated in this release

cart/shipping-calculator.phpWording of Country updated to Country / Region in shipping calculator
global/quantity-input.phpAdded placeholder attribute for the quantity input
emails/customer-reset-password.phpAdded missing tag for the end of paragraph
emails/email-styles.phpUpdated img CSS
emails/email-header.phpSet table width to 100%
single-product/add-to-cart/grouped.phpAdded placeholder attribute for the quantity input

For more details check here: