Categories
WooCommerce

Displaying regular price alongside sale price in variable and grouped products

In most cases, when a product is on sale, WooCommerce displays the (crossed-out) regular price alongside the price on sale. This is a great way for customers to see how much they’re saving on a product.

One of my pet peeves about WooCommerce is that, when it displays a price range (which can happen in variable and grouped products), it only shows the final (on sale) price.

How WooCommerce displays the price tag in a simple product on sale, versus how it does in a variable product on sale. The simple product displays the crossed-out regular price of the item, alongside the sale price. In the variable product, only the sale price is displayed.
Price before discount appears alongside sale price in the simple product, but not in the variable product.

I get the reason behind it. Showing two price ranges one alongside another results in a very long, aesthetically-unappealing price tag.

But for me, there are other options that are preferable to hiding the regular price altogether (such as tweaking the result with CSS).

If you, like me, would like to modify WooCommerce’s default behavior to display the regular price anyway, keep reading. You can also find the final result on Github.

Categories
WooCommerce

Adding custom fields (metadata) to WooCommerce product attributes

Imagine the following scenarios:

  • There’s a product filter that makes use of product attributes. The shop manager wants to be able to choose if a particular product attribute is displayed in the filter or not.
  • There’s a pre-defined list of product types that are sold in a store. The shop manager wants to be able to associate product attributes to one of the product types. Products of a certain type have their associated product attributes automatically added to them.

These are cases where we could benefit from being able to associate product attributes to custom data. Unfortunately, this isn’t as simple as it could seem at first glance. We cannot use the WordPress metadata API as we would with posts and terms.

In this tutorial, I’ll explain my approach to associate custom data with WooCommerce product attributes. You can also find the final result on Github.