WooCommerce: View Stock History @ Product Admin

When questions such as “How do you save the product stock inventory history?” pop up in our private Business Bloomer Club slack channel for WooCommerce developers, I can’t really do without thinking of coding it myself!

This neat customization saves the stock quantity of a simple product or a variable product variation before there is a stock change, due to a manual stock quantity edit or a customer order.

Please bear in mind that if you have hundreds of stock movements per product this may slow down your backend and/or database, so the snippet may need some sort of optimization or limitation (“last 10 movements”).

So, let’s see how it works. Enjoy!

Continue reading WooCommerce: View Stock History @ Product Admin

WooCommerce: Alter Product Search @ Manual Admin Orders

Ok, we’re in a niche of a niche this time – manual orders (orders created by the WooCommerce administrator). If you’re familiar with that, the admin would click on “Add order“, fill out the billing & shipping information, and then move to the order items section, where they can add products to the order.

As soon as they click on “Add items” > “Add products“, a table displays with a product search and quantity input. That’s exactly where we’re working today: what if you have 10,000 products in your store, but only create manual invoices with the same 2-3 products? In this case scenario, it makes no sense to search for the whole 10,000 product list and wait for WooCommerce to return a result (slowly) – it’s much more efficient to reduce that list to a specific category or a list of IDs so that the search operations can be faster.

Here’s how it’s done. Enjoy!

Continue reading WooCommerce: Alter Product Search @ Manual Admin Orders

WooCommerce: How to Bulk Generate Coupons Without a Plugin

There are times when doing manual work – such as creating a WooCommerce coupon – is too time consuming. Imagine you need to bulk generate 1,000 coupon codes – sure you have 2,000 minutes at your disposal to do it all by hand?

Well, today, we’ll take a look at how to bulk generate coupon codes from the WordPress backend by using a simple PHP “for“. Once the function triggers, it will just be a matter of seconds!

Enjoy!

Continue reading WooCommerce: How to Bulk Generate Coupons Without a Plugin

WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now

I just spent the last 3 days in Porto with another 2,300 WordPressers at the first in-person WordCamp Europe since Berlin 2019. I had a blast, held a nice (yet long) workshop, spoke to many, but got tired too soon.

Later on, I realized that that tiredness was something more serious – in fact I tested positive against COVID for the first time in my life, and I’m now in self-isolation hoping it won’t last long… Another 7 days without my kid – send help!

Anyhow, what really struck me at WCEU 2022, and based on various chats and some data that I’ll share below, is that the WooCommerce ecosystem is in trouble.

A nicer way to put that? WooCommerce is not moving forward as fast as it should, and unless some key issues are addressed right now, in a few years time we all may pay the consequences.

Please note, this is not a rant. It’s a proper analysis, full of actionable information.

@ WooCommerce team - if you're reading this - my plan is to give you constructive feedback and tell you what the community (really) thinks, needs and wants, so that you can get a better picture of the current situation. I know you've already started working on this, so this is just a recap/reminder and a way to get the whole community realigned. 

In this post, I will share my worries, my fears, the current WooCommerce issues, some data I collected at WCEU 2022 and then a list of actionable solutions that may be implemented in order to clear the backlog and get back on track – asap. Enjoy!

Continue reading WooCommerce: 10 Crucial Issues That Should Be Fixed Right Now

WooCommerce: View Thank You Page @ Order Admin

I’ve been testing for over an hour but finally I found a way to make this work. When you are in “Edit Order” view under WordPress Dashboard > WooCommerce > Orders, there is a dropdown of “Order actions”: “Email invoice”, “Resend new order notification”, etc.

A major problem I’ve always had while troubleshooting or working on the WooCommerce thank you page was that I had to build that URL by hand in order to view it again or to avoid placing yet another test order (it follows the format e.g. https://example.com/checkout/order-received/214008/?key=wc_order_aHB6YrmLOZIKP).

Well, from today, you can access that order thank you page URL directly from the “Order actions” dropdown. Enjoy!

Continue reading WooCommerce: View Thank You Page @ Order Admin

WooCommerce: Add Custom Field to “Quick Edit”

WooCommerce product custom fields are possibly the most used customization from what I’ve seen over the years on clients’ websites.

Adding custom fields to the product backend is pretty straight forward (including the input fields to be used for editing their values), however there are two additional areas where you need to do more work in order to allow for custom field editing: the “Quick Edit” and the “Bulk Edit” sections (WordPress Dashboard > Products).

We already saw how to allow a new custom field to appear in the Bulk Edit section, so this time we’ll talk about the Quick Edit window. So, how do we add a custom field in there (WordPress Dashboard > Products > Hover on a given product > Quick Edit)?

Well, here’s a fully working snippet for you. Enjoy!

Continue reading WooCommerce: Add Custom Field to “Quick Edit”

WooCommerce: Create Product Programmatically

No matter if this snippet suits your needs or not, it’s still interesting to see how you can create a brand new WooCommerce product programmatically / automatically when a certain even triggers.

In this case studio, we’ll see how to generate a brand new product, set its featured image, price, category, title and a download file as soon as an image is uploaded in the WordPress backend Media section. This would be super useful for photographers for example – simply upload a new image to the WordPress Media Library, and a new product is automatically created.

Of course, you can customize the code and use it with different triggers. For example, you may need to create a new product automatically when each phone product needs always a matching case product, just with a different title. Or maybe you want to tie product creation once an order is placed.

Either way, enjoy!

Continue reading WooCommerce: Create Product Programmatically

WooCommerce: Sort Products By Stock @ Admin Dashboard

We’ve already seen how to sort frontend products by in stock first and out of stock last, but what about doing the exact same for administrators and shop managers in the backend?

Sometimes shops have to deal with a lot of “sold” products and the products table becomes messy, so this is a way to sort by stock status (In stock -> Out of stock) on load. You can then use the column headers to sort by other data as usual, so this will only work once you access /wp-admin/edit.php?post_type=product page.

So, here’s a very simple snippet for you. Enjoy!

Continue reading WooCommerce: Sort Products By Stock @ Admin Dashboard

WooCommerce: Force Max 1 Category Per Product

Here’s yet another snippet I use on A Piece of Sicily, my Sicilian marketplace, to make sure vendors can only select one product category for a given product. This is to make sure they make the best possible choice and also to avoid confusion and multiple listing.

Of course, the same can be used on your own WooCommerce install, in case you wish to limit the number of categories that can be assigned to each product (inside the snippet, you can even change “1” to “whatever number” and therefore define your own “max” e.g. max 2 categories).

This time I can’t make you “see” the customization as we’re in the backend, so please take a look at the screenshot below. Enjoy!

Continue reading WooCommerce: Force Max 1 Category Per Product

WooCommerce: Find Products With No Weight @ WP Admin

If your shipping rates depend on product weight, it is very likely you’ve forgotten to add weight to ALL your products. In this way, some shipping rates may be underestimated on the WooCommerce Checkout page.

So, here’s how to print a notice on the WordPress Dashboard > Products screen with a list of products that have no weight, together with the links to edit them quickly.

This is a handy snippet you can reuse for other case scenarios such as easily finding products with no dimensions, no prices, no images, no custom field value, or even a specific weight or given price. Enjoy!

Continue reading WooCommerce: Find Products With No Weight @ WP Admin

WooCommerce: Add Product Table Columns @ Admin

The default WooCommerce Dashboard Products page (/wp-admin/edit.php?post_type=product page) shows the list of products in a table. Default fields are: Image, SKU, Stock, Price, Categories, Tags, Featured and Date.

Sometimes, these columns are not enough and you need more. For example, you might want to quickly take a look at a product custom field, such as “visibility” (whether the product is hidden or not).

So, here’s the snippet for that. Of course, you can adapt it to show your own custom field, an ACF field or whatever product-related information you require.

Continue reading WooCommerce: Add Product Table Columns @ Admin

WooCommerce: Add Custom Field to “Bulk Actions” > “Edit”

As you know, one of the product bulk edit methods comes with WooCommerce out of the box. It can be found under “WP Dashboard” > “Products” > “Bulk Actions” > “Edit”. For example, you can decrease all prices by 10%, or bulk assign a new product category.

However, if you added a custom product field such as RRP, this won’t show automatically there in the bulk edit form – you’ll therefore need to add it via code. Thankfully, WooCommerce gives us a “hook” we can use to display the input in the bulk edit form. After that, another PHP function will be used to save and store the value.

Easy as pie! Just copy & paste into your functions.php. Enjoy ๐Ÿ™‚

Continue reading WooCommerce: Add Custom Field to “Bulk Actions” > “Edit”

WooCommerce: Add Second Description @ Product Category Pages

In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products.

Nothing new so far. But what if you want to add another piece of content below the category products while also keeping the default description? Well, we’d need to customize the edit category page and display a new text editor field, save it, and finally display it where we want. So, here’s how they do it!

Continue reading WooCommerce: Add Second Description @ Product Category Pages

WooCommerce: Add Custom Page @ WordPress Admin Dashboard

If you’re developing custom WooCommerce documentation, reporting or functionalities for your clients, you probably also need to add a new “page” and a new “sidebar link” to the WordPress Admin Dashboard.

This is a very interesting topic and in the same way you can hide elements such as metaboxes, you can also add new ones. In my case, I had to implement a custom, admin-only form to enable product recommendations. Enjoy ๐Ÿ™‚

Continue reading WooCommerce: Add Custom Page @ WordPress Admin Dashboard

WooCommerce: Remove “Metaboxes” @ Product Edit Admin Page

Let’s say you disabled product tags in your shop. Or maybe your store set up requires no short description. Or even, you want to hide a custom “metabox” (e.g. one of those widgets that appear on the Edit Product page). Either way, removing metaboxes and making the Edit Product page much cleaner is quite easy.

You just need the “ID” of the metabox and its position (‘normal’ or ‘side’, depending on whether it’s in the sidebar or not), and then this little PHP snippet. Enjoy!

Continue reading WooCommerce: Remove “Metaboxes” @ Product Edit Admin Page

WooCommerce: Set Default Dashboard Login Page to “Products”

When you log in to the WordPress dashboard and WooCommerce is active, you might want to be redirected to a different page rather than the default “Dashboard” one.

For example, you might want to go directly to the “Products” admin page, or maybe to the “WooCommerce > Orders” page. Or, if you are like me on my development website, you want to go straight to the WordPress editor’s functions.php file ๐Ÿ˜€

Either way, saving time on login is what we’re chasing here. Pick your default login page, and then use the two snippets below to target actual logins and direct accesses to wp-admin. Enjoy! Continue reading WooCommerce: Set Default Dashboard Login Page to “Products”

WooCommerce: Disable Update Notifications @ WordPress Dashboard

We talked a lot about safely updating WooCommerce. The same applies to WordPress core, other plugins, themes… WordPress is such a delicate piece of software that you should ALWAYS know what to do before actually doing it ๐Ÿ™‚

Sometimes, website managers feel great about clicking on that “Update Now” link in their WordPress dashboard. It seems – and it is – so easy. Problem is, they’ll likely break the website.

The best way of doing this properly is to run the updates (as well as custom code, plugin tests, design changes) on a “staging environment“, which should be provided by your hosting company.

Either way, those “Update Now” links are too dangerous. Only you (the developer) need to know that – while it’d be better if the other users who have access to the dashboard didn’t see anything and concentrated on WooCommerce orders or WordPress post and content editing.

Clearly, there is a way to disable the update notifications on a per-user basis or, even easier, to only have 1 user (possibly you) see these. The snippet is a little complex, but there is a lot of literature online – this is the one that worked for me! Continue reading WooCommerce: Disable Update Notifications @ WordPress Dashboard