Blog

Importing Products in Multisites

Recently I was testing my new plugin related to a multisite network of WooCommerce stores and noticed that before doing a product import into one of the stores in a network you first need to do some additional network configuration.

I mean if you just go to a product import and try to upload a CSV file for example, you will definitely get an error like that:

product import error when importing WooCommerce product in a Multisite network
Trying to upload a CSV or TXT import file will cause this error when running a WooCommerce store within a multisite network. The error message can be like on the screenshot “Sorry, you are not allowed to upload this file type” or “Sorry, this file type is not allowed for security reasons”.

Understanding HPOS (High-Performance Order Storage)

In this tutorial I would like to guide you through the High-Performance Order Storage (HPOS) feature in WooCommerce – how to turn it on for your store, how it may affect it and how to update your plugins in order to make them work with the latest WooCommerce versions.

How to Copy a Page from One WordPress Site to Another

In this tutorial I would like to cover two ways how you can copy a WordPress page from one site to another. I am not going to use the export and import approach, because I think it is too complicated and requires extra steps which we normally don’t need.

And of course everything in this tutorial applies not only to regular WordPress pages, but also:

  • pages with tons of custom fields (ACF, Carbon Fields, Simple Fields etc),
  • pages, created with page builders (Elementor, WPBakery, Beaver Builder etc).
  • pages, created with either classic or the block editor.

So let’s get started now.

Bulk Update Product Stock Quantities

In the previous tutorial we already discussed updating WooCommerce product stock quantities programmatically when we covered how to do it with REST API specifically.

The whole idea can be deconstructed into two simple things:

  1. Connect to woocommerce_product_set_stock (or woocommerce_variation_set_stock action hooks for product variations).
  2. Send a REST API request to /wc/v3/products/{$product_id} (or /wc/v3/products/{$product_id}/variations/{$variation_id} for product variations).

That’s pretty much it. But there is a “but”. If a specific WooCommerce order in your store can contains a lot of products, then you have a problem. For example, there are 50 products in a single order, then guess what? 50 REST API requests are going to be sent in order to sync all the products stock quantities.

So there is no other way than to update the stock quantities in bulk. But how to do it?

Disable REST API without Plugins

Before I provide you a code snippet which you can copy and paste to your functions.php or something I would like to discuss why do even need to disable JSON REST API in WordPress?

The long story short is to provide less information about your website to those who shouldn’t probably have it. For example if we add at the end of site URL /wp-json/wp/v2/users, we can list all the registered users! Without emails of course but anyway.

If you want to prevent this from hapenning, you can either disable WordPress REST API completely or just its specific endpoints. And that’s what we’re going to do in this guide.

Sync WooCommerce Customers Between Stores

We already know from my previous tutorial how you can sync WordPress users between sites using REST API. And I also have a plugin for that. But today we are going to make it a little bit differently – for WooCommerce customers using WooCommerce REST API.

Once again I have plenty of tutorials about WooCommerce REST API on my blog, so those who already had a chance to work with it, they will learn nothing new here, I guess.

Indeed, the example in this tutorial is quite simple – we are going to go to any user profile settings, hit “Update User” button and we expect those changes to be reflected on the other WooCommerce store. As simple as that.

Create Tabs in Meta Boxes

Recently I published another tutorial where I created tabs for WordPress settings pages. We didn’t even discussed the design moment there, because WordPress core has everything we need, we just used a wrapper element <nav class="nav-tab-wrapper"> and two CSS classes for tabs nav-tab and nav-tab-active. That’s pretty much it.

With meta boxes for posts this moment can be a little bit tricky. We can of course use the same approach we used for settings pages and then our tabs are going to look like this:

meta box tabs like in WordPress settings pages

In this example we have a couple of disadvantages:

  • These tabs aren’t going to work by default, so we need to add some JavaScript which is going to switch the tabs.
  • I also added some custom CSS for tabs – background-color and border-color, otherwise they looked really ugly.

Or we can try the tab design WooCommerce uses:

Tabs in WooCommerce product meta box

Tabs look nicer but in this case we have to copy all the CSS from WooCommerce when it is not installed on our site. And don’t fotget JavaScript. So it is similar to the “option pages-like” tabs way but maybe even more complex.

Suddenly I found a solution when I took a look at categories meta box:

meta box with post categories in WordPress

When I tried to copy and paste it for my custom meta box I found out that it works as is, that we don’t even have to add any extra CSS or JS! So, it seems to be exactly what we need. And this is how our final meta box in this tutorial is going to look like:

create tabs in WordPress meta boxes
Organizing fields by tabs in WordPress meta boxes.

As always I am going to show you two approaches here:

  1. Completely from scratch. In this case the tutorial about meta boxes is recommended to read.
  2. With my plugin. Just copy and paste the code plus different field types are supported.