Blog

Change Related Products Text

Change or Remove Sale Badge

WooCommerce sale badge is displayed automatically for products that are currently on sale. But what if you don’t like its default design or maybe you would like to change its text or even to completely remove it. We will dive into it in this tutorial.

Get Number of Items in Cart

Let’s skip the introduction part and get straight to the solution. There are actually two ways depending on what you are going to achieve:

  • WC()->cart->get_cart_contents_count() – it allows to get a number of cart items including their quantity counts. For example, if you have 10 snowboards and 1 avocado toast in the cart, this method will return 11! You can see it yourself if you open this method in WooCommerce source code. It just gets the whole cart array from WC()->cart->get_cart() and then for each item it gets its quantity parameter.
  • count( WC()->cart->get_cart() ) – this implementation actually returns the number of unique products in the cart, one per product.

How to Get Default Page URLs

If you go to Pages > All Pages after WooCommerce installation, you will notice that a couple more pages appeared there. These are kind of system pages in WooCommerce and required to provide your shop visitors proper eCommerce user experience.

The WooCommerce default pages – Cart, Checkout, Shop, My Account

Sometimes, and I might say – very often, when coding something for WooCommerce we need to get these pages URLs programmatically. We can’t use something like site_url( 'cart' ), because website administrators allowed to change the system pages URLs, for example to use example.com/basket instead of example.com/cart and so on.

Luckily there are a couple functions in WooCommerce that allow to get these page URLs dynamically.

Hide Marketplace Suggestions in WooCommerce

Remove Unwanted Widgets in WooCommerce

Okay, now we continue with cleaning up WooCommerce admin from the unneeded stuff. In this tutorial I suppose that you or your client does not need all the default widgets that appear after you install the WooCommerce plugin.

And by the way – at the moment of creating this tutorial I didn’t find a list of default WooCommerce widget names anywhere over the internet, which of course surprised me. So I retrieve all the widget names directly from the code.

How to Safely Remove Product Tags in WooCommerce