WooCommerce snippets

On this page we present you our constantly growing collection of WooCommerce Snippets (code snippets) to expand your WooCommerce shop with useful functions without additional plugins. The integration is very simple, programming knowledge is not necessary. You can choose to include them in your functions.php of your theme / child theme, or you can use the plugin Code snippets for WordPress.

The installation of this snippet is at your own risk, we assume no liability for it. We definitely recommend that you create a backup beforehand. But it is best to test it first in a development environment, which you can do with just a few clicks WP staging create.

Do you have any other optimization tips for WooCommerce? Feel free to leave a comment below.

Please note that this collection is free and will be expanded, but we cannot offer free support for WordPress or WooCommerce. Please use appropriate forums for this. We are also happy to make you an offer for individual solutions. Just ask.

Frontend

Adapt translations and texts

The German translation for WooCommerce is very professional, but every now and then it happens that individual words or sentences still want to be phrased differently or have not yet been translated. Without touching the translation files right away, because these would probably be overwritten in the next update, this can be solved with a simple and permanent trick. Replace "Choose an option" with the phrase or phrase you want to change. Replace "Select" with your translation. If you would like to make several translations, simply copy the entire line and paste it under it again.

Remove comment field on checkout page

This simple snippet hides the comment box on the Checkout page. We use it in some of our shops because the ordering process and the processing of the orders run automatically and the field is simply ignored. Customers often write notes on delivery that are not printed on a parcel label anyway, so we decided to remove the field.

Add an additional checkbox on the checkout page

There are as many reasons for additional checkboxes on the till side as there are shops. One of our customers, for example, sells products that can only be purchased from 16, so he wanted an additional checkbox in which the customer confirmed that he was at least 16 years old. The order should not be sent without clicking the corresponding checkbox. If you try to send the order anyway, you will be informed accordingly.

Cross out the subtotal and display the new price in conjunction with a voucher

This snippet is used in conjunction with a voucher. The original subtotal in the shopping cart is crossed out and the new, discounted price is displayed. If desired, the line with the voucher can then be hidden with a little CSS.

Show amount 0.00 € with free shipping

In previous versions of WooCommerce, the amount 0.00 € was displayed behind the shipping method for free shipping. With this little snippet you can undo or restore it

Hide prices for unregistered users

One of our customers only sells his articles to B2B customers and they have to register beforehand in order to shop. His wish was to hide the product prices for unregistered users / visitors.

Show YouTube video as a product image

One of our customers only sells his articles to B2B customers and they have to register beforehand in order to shop. His wish was to hide the product prices for unregistered users / visitors.

Insert the product image and article number in the email order confirmation

The order confirmation by email is not only a legal acceptance of the order, but also an important instrument to provide the customer with all possible information about his order. The more, the more secure the customer feels in his decision, he has a positive shopping experience and fewer questions. Unfortunately, the product pictures and the article numbers are not available in the WooCommerce order confirmation as standard.

Number of keywords in the tag cloud

At a WooCommerce shop, we recently found that WordPress limits the number of keywords in the Tag Cloud widget to 45 by default. With this snippet you can adjust the number at "number" as you like.

Show category pictures in the template

Have you ever wondered that WoooCommerce can upload an image for every category, but then asked you why the image is not displayed? This function is not built into WooCommerce and not every theme supports it, but there is also a simple solution for this.

Hide information about the voucher on the checkout page

Again in tip in terms of usability. If you have activated the voucher function at WooCommerce, a note about entering the voucher code is displayed on the shopping cart and checkout page. However, if a customer has already entered and activated the voucher on the shopping cart page, such a notification on the checkout page is superfluous.

Prices from instead of to for variants

Perhaps you are also one of those people who would prefer to have a price with the note "from" instead of the price display for variants "from to".

Insert tab for each product with the same content

For WooCommerce there are also some plugins to add further tabs for products in addition to the tabs Description and Reviews. If you are looking for a lean way to insert a fixed tab for all products, this code will help you. The number in Priority indicates the order of the tab. Depending on which numbers the other tabs have, this is inserted accordingly. The larger the number, the further to the right or below is the tab.

Show number of sales for product

Ebay does it, other online shops do it too, they show the number of sales for each product. This not only creates transparency and shows how much a product is in demand, but it also shows above all the trust of customers in the product.
You can adjust the text as you like. You can vary the order or placement of the line in the frontend with the number "11" in line 1.

Show offer period for the product

With WooCommerce you can set an offer price and a period of time for each item from when to when the offer is valid. Now there are always situations in which your customers ask themselves how long the offer is still valid. Save your customers from asking and answering by showing the end date of the offer for the product. If necessary, adapt the text and the output of the date to your wishes.

Minimum order value for the entire shop and display of a notification if the value is undershot

Sometimes you have to or want to set up a global minimum order value in your shop because it is not economically worthwhile to allow and process orders beforehand. You can implement this in your shop with this simple snippet. Simply replace your minimum order value and adjust the hint or error message if necessary.

Show savings in % for product

Here is another sales promotion. Make it easier for your customer and show them their savings in percent. This snippet automatically calculates the savings in % for an item with an offer price. The display takes place on the product page as well as on the category page.

Show savings in € and % for product

Here is another sales promotion. Make it easier for your customer and show them their savings in € and percent. This snippet automatically calculates the savings on an item with an offer price. The display is on the product page and can be customized using a separate CSS class.

Show other shipping methods even if free is available

With the update to WooCommerce 2.6, the complete setting for shipping has also changed positively, there are now many more options with regard to shipping zones and shipping settings.

Now we had the case for a customer who, like many other retailers probably also offers standard shipping, wanted to offer free shipping from a certain amount and also express shipping. We have renamed the pickup on site in the shipping settings to express shipping, because pickup on site is not offered.

By default, all other shipping methods are hidden at WooCommerce as soon as free shipping is offered. In our case, of course, the express shipping or the pick-up on site was also hidden.

With this snippet the problem can be solved.

Show date of product release on product page

Show your customers when you added the product to your catalog, the big players do it too.

Display the category description below the products

By default, the category description in WooCommerce is shown above the products. If you have now written a nice long SEO text, the customer must first scroll before he gets to the actual products. In most cases, the customer does not read the text anyway 🙂 With this small snippet you can display the text of the category description below the products.

Only add text behind the price for certain products

Every now and then would like to display additional information behind the price in WooCommerce. We now had the case for a customer who sold configurable products and behind the price the information "basic scale price" should be displayed. With this small snippet you can do this depending on the product ID. This information is displayed on the product page and in the shop archive.

Hide the name of the shipping method in the shopping cart

WooCommerce also shows the name of the shipping method in the shopping cart. In some cases, this does not look very nice, since all other prices in the shopping cart are displayed one below the other, just not the one for shipping. If you can afford it now, for example because you only have one shipping method and one shipping price, you can use this small snippet to hide the shipping method. "Free delivery" and "On-site pickup" are not affected. This snippet only removes the display in the shopping cart, in the mails and the order details the shipping method is still displayed.

Add fee to cart and checkout

If you want to charge a fixed fee for your orders, there are many reasons for this, you can achieve this with a small snippet. Of course, the taxes for the fee are calculated accordingly and the fee is also shown in the order details.

What is Paypal remove in the payment method on the checkout page

Not everything makes sense and is also not visually attractive. With this small snippet you can remove the link "What is PayPal" from the payment method PayPal on your checkout page.

Add your own text on the login page

Feed your customers with additional information on the login and registration page. For example about the advantages of registration or what the customer can expect when he has logged in. The possibilities are almost limitless with this snippet.

Move similar products to a new tab

If you want to move the "Similar Products" into a new tab for optical reasons, you can do this with this snippet.

Notification in the shopping cart when a certain product is in the shopping cart

If you want to let your customers see a notification as soon as a certain product is in the shopping cart, you can do so with this snippet.

Telephone is not a required field

If you want to prevent the Telephone field from being a mandatory field on the Checkout page, you can use this snippet.

Automatically add voucher in the shopping cart for sale campaigns

The less work the customer has, the more conversions you can achieve. So why not automatically activate a voucher in the shopping cart, so the customer no longer has to enter it. With this snippet you can activate a voucher code of your choice in the shopping cart. However, the customer must go to the shopping cart page, otherwise the discount will not be applied.

Show savings in shopping cart and checkout

To convince a customer to buy on your site is difficult enough. Why not help out with a little psychological trick? If the customer has products in the shopping cart that are on offer, the total saving is shown on the shopping cart and checkout page using this snippet.

Additional information directly via shopping cart

The properties of products at WooCommerce are displayed in the "Additional information" tab. Is not now logical and can easily be overlooked. If you now display this information directly above the shopping cart button, it will definitely not be overlooked.

You can hide the unnecessary tab with Custom CSS:
.product .woocommerce-tabs .tabs .additional_information_tab {display: none}

Check whether the house number has been entered at the address

It is annoying when you receive an order, but the customer has forgotten to include his house number in the address. This creates an additional effort for the demand.

This snippet corrects the problem and checks address line 1 in the ordering process, both billing and delivery address, for a number. If there is no number in the field, a corresponding error message is output.

Note on the checkout page depending on the country selected
WooCommerce Snippet emoose GmbH - Note on the checkout page depending on the selected country

Sometimes you need a solution to display a note to buyers from abroad. We use the function, for example, for free returns through PayPal and recommend that buyers pay with PayPal.
This snippet is suitable for this, depending on the country of the billing address there is a corresponding note.

WC 3.3 Hide category Uncategorized

With this small snippet you can hide the "Uncategorized" category that has been around since WooCOmmerce 3.0 in the frontend.

Note Remove items placed in the shopping cart

With this small snippet you can hide the hint that an item has been added to the shopping cart. Very helpful if you have a shopping cart widget, for example, then the hint is superfluous.

Empty shopping cart function

Why should you offer such a crazy function? Quite simply, you should try everything to make life as easy as possible for your customers. So instead of deleting each article individually, you can now delete the entire shopping cart with a single click.

Order now quickly before sold out

If you have activated inventory management in WooCommerce and activated the threshold for low inventory, this function is user-friendly and encourages you to buy.

As soon as the inventory reaches or falls below the threshold, a freely definable message is issued in the front end of the product.

Display shopping cart remaining amount until free shipping

Encourage your customers to buy something more! For example, with a note in the shopping cart which amount is still missing until shipping is free.

WooCommerce Description Product category with text above and below

Anyone who runs a shop should sooner or later also deal with the topic of SEO. If that doesn't mean anything, you don't need to read on from here.

To describe your product categories there is only one field to insert a description there. If the theme supports it, this is then displayed directly below the heading. (Please note, there is also a snippet above to display the description below).
The more text there is, the higher the probability that your users will not read it and it doesn't look particularly nice either.

So why not add a short description above and a detailed description below with much more information? Not only Google is happy, but also your visitor.

You can implement this with this snippet. Have fun

Mail to customer when order is canceled

By default, only the admin receives an email when an order is canceled. The customer also receives a notification with this snippet.

Admin & backend

Enlarge product images in the backend

The product images in the WooCommerce backend in the "Products" overview may be a bit small for some users, but this can be changed easily and that's why we love WooCommerce

Add link in the WP Admin Toolbar

As an admin of a WordPress site, you want to make life as easy as possible for yourself and your customers. We also do that Fulfillment for some of our customers and have an additional link built into the admin toolbar, so they can simply access the fulfillment statistics and do not have to save another bookmark. You also have a lot of ideas for further links in the admin toolbar.

This small snippet makes it easy to do.

BCC completed order emails

WooCommerce sends an email to the customer when the order has been completed, but unfortunately not to you as the shop operator. With this simple snippet you will receive this mail in BCC. Just replace your name and email address.

BCC all WooCommerce emails

WooCommerce sends some emails to the customer, but unfortunately not to you as the shop operator. With this simple snippet you will receive all WooCommerceMails in BCC. Just replace your email address.

Reply To function for email order confirmation

As a shop owner, you can have an email sent to you for a new customer order. If you then click on reply in your mail program, because you might want to send the customer an info, you practically send this mail yourself, because you answer the sender of the shop. This snippet automatically enters the customer's email address when replying.

Add prefix / suffix to order number

Whether for optical or organizational reasons, with this small snippet you can add a prefix and a suffix to your order numbers in WooCommerce.

WooCommerce new order status

Sometimes an additional order status is simply required, there can be many reasons for this. We have, for example, a new order status "In Backorder"
inserted because we allow an order for some products despite the stock being sold out. So that we do not lose the overview, we simply put the order in the new order backlog.

Show total number of sales in product overview

With this small snippet you can add a column with the number of units sold in the product overview in the backend.

WooCommerce automatic forwarding to order overview after login

If you can simplify your life, you should do it too. It is a daily ritual for many of you. Log in to WordPress and then to the WooCommerce order overview to process the orders. With this snippet you will be automatically forwarded to the order overview after logging in.

164 thoughts on “WooCommerce Snippets

  1. Ralph says:

    Hello everybody,

    I came across you by chance - ingenious collection to mean that I already have. THANK YOU. I'm already busy testing. 😀 I have been wondering for a long time whether it would also be possible to remove this unnecessary 2nd address line in Europe without CSS. Similar to the comment field in the cash register. Now just on the "My Account" page. ... Or at least "solve" this one line as a mandatory field if you do not enter anything. It only confuses. Would be mega if someone had an idea. Kind regards

    • emoose says:

      Hello Ralph,

      this is possible

      add_filter ('woocommerce_checkout_fields', 'custom_override_checkout_fields_ek', 99);
      function custom_override_checkout_fields_ek ($fields) {
      unset ($fields ['billing'] ['billing_address_2 ′]);
      unset ($fields ['shipping'] ['shipping_address_2 ′]);

      return $fields;
      }

  2. Hannes Stark says:

    Hello everybody,
    I have a problem working with a product with packaging units and at the same time showing the unit price in a loop. So, for example, “surgical masks” at € 0.55 - in a package of 50 pieces - at the price of € 50 × 0.55…
    In the product loop the price is then € 0.55, on the detail page you can order x packages of 50 pieces each for the price x times (0.55 x 50) and ideally the unit price is also shown separately. I tried the configurable products, but it looks like this type of price breakdown cannot be represented with it ...
    I'm desperate, maybe you have an idea or an approach?
    Thank you so much!

    • emoose says:

      Hello,
      so wich would solve it that way. Would create the product as a variable product, retail and packaging unit. I would then enter the base price for both. Already solved.

  3. Niki says:

    Hello,

    I am looking for a way to send an info email to the customer if I set the status Cancellation / Canceled in the backend or if I cancel the WC. So far this mail only goes to the admin.

    Do you have a solution to this?
    Thank you in advance!!!

  4. Sebastian says:

    I need a snippet with which I can remove the link to the cancellation policy from the shopping cart page.

        • emoose says:

          Unfortunately, we cannot help without information about your site. In general there is no link to the cancellation policy on the shopping cart page. Check times in the settings of your theme or plugin for legal security, because you can actually deactivate it.

  5. Felix says:

    Hello emoose team
    Do you have a snippet to set different minimum order values for free delivery in different shipping classes?
    For example:
    - "Standard shipping class" shipping costs CHF 4.90.-, free shipping from a minimum order value of CHF 200.-
    - "Bulky goods shipping class" shipping costs CHF 80.-, free shipping from a minimum order value of CHF 3000.-
    Thank you so much!

    • emoose says:

      See if they can:
      https://de.wordpress.org/plugins/woo-extra-flat-rate/
      https://woocommerce.com/products/table-rate-shipping/

  6. Felix says:

    Hello emoose team
    This is a really great collection of WooCommerce snippets!
    Is there a way with a snippet to make the delivery time of a product dependent on availability. So, for example, if a product is in stock delivery time 2-3 days and if the product is backordered, depending on the manufacturer, deposit 2-3 weeks or 5-8 weeks?

Leave a Reply

Your email address will not be published. Required fields are marked *