Woocommerce Bulk database post_meta fix for guest checkout

12Flat.com Woocommerce Bulk database post_meta fix for guest checkout

Woocommerce Guest Checkout Fix

Many of our clients have thousands of products in a Woocommerce store, some who are running a complex WordPress membership site.  The power in using various Woo extensions and plugins, managing products and users in guest and member checkout scenarios (logged in users, creating members and non subscriber purchases) can be daunting for those not comfortable working in php, mysql and phpmyadmin especially inside the database on a live site. It’s Friday after a long week and we’ve identified a solution to separate physical orders from memberships while still allowing guest checkout on a “sub-set” of categories.

The problem is that the plugin to enable guest checkout on certain products can only be turned on manually, one product at a time. There are too many products in this site to do this manually and the plugin is not advanced enough to bulk-apply to categories or to use the native “quick edit” function in the post/product list. Woo commerce itself is on/off for guest checkout in its own settings, no middle ground.

Without writing a new plugin or other options at our disposal the task seems a bit daunting on the surface. Facing you is about 1500 products in 20 categories and 20 membership/subscription levels. The current board of directors has stated that since having always issued member cards with unique numbers on them for well over a half a century, we’re not going to start allowing guests to create random WordPress users among the already congested CRM used for member maintenance, user tracking and marketing (payment reminder emails etc.).

So, it’s off to PhpmyAdmin we go, looking for the meta that chrome tools inspection points to  – “_allow_guest_checkout“.

Since everything in Woo commerce is WordPress derived, a product is simply a custom post type with a post_id and lots of xx_postmeta similar to xx_usermeta. Big tables these ones, thousands of rows.

Once we isolate the row for the product we used the plugin to allow guest checkout we see it’s dead simple.

meta_id post_id meta_key meta_value
190897 4892 _allow_guest_checkout yes

The object of the lesson is to create all the products in the database their own row like product 4892 above, which is a Trade Handbook sought often by the members. We know the post_id’s for all the products and we’re excluding subscription based products (membersips) which we prune out from the sortable rows in the export file of products. (xx_posts to be exact).

The way WordPress generates meta_id’s can look random to the un-trained, but DO NOT get this part wrong or one incorrect number could break a lot of stuff instantly. Of course we do this in a controlled staging area but it’s no different when you make it live. A good backup is always necessary. We love to “measure twice, cut once” then charge in guns-a-blazing, generally it works the first time.

The secret of generating the meta_id is simple. In the xx_postmeta table the meta_id is exactly as depicted above. Double check this, just click the actual header “meta_id” in PhpmyAdmin and it will sort ascending, then again, descending.  The large number is the “last” meta_id generated by the system. In other instances we use an auto-increment sql syntax to alter how WordPress generates certain things, but not here. We’re just going to generated a number starting at, for instance 192,000, based on the largest number above we’re just saying leave a gap, the amount is purely personal. The 1500 rows of post_id are fixed to the products, the meta_key(s) are ALL _allow_guest_checkout and the meta_value(s) all yes.

The first 15 rows will look something like this:

meta_id post_id meta_key meta_value
192000 6324 _allow_guest_checkout yes
192001 5153 _allow_guest_checkout yes
192002 6125 _allow_guest_checkout yes
192003 6454 _allow_guest_checkout yes
192004 4016 _allow_guest_checkout yes
192005 3735 _allow_guest_checkout yes
192006 4922 _allow_guest_checkout yes
192007 5756 _allow_guest_checkout yes
192008 5575 _allow_guest_checkout yes
192009 6283 _allow_guest_checkout yes
192010 6122 _allow_guest_checkout yes
192011 6571 _allow_guest_checkout yes
192012 4956 _allow_guest_checkout yes
192013 6103 _allow_guest_checkout yes
192014 6118 _allow_guest_checkout yes

Save this as a plain CSV and upload it to the xx_postmeta table and bingo all the boxes are checked in the affected products in the WordPress Woocommerce product dashboard.

If you want to get into some real mind bending exercises, we’re right now juggling some Woo related UPS and USPS shipping calculations that we’ll write about soon. Enjoy:/

Author: Stuart Liedtke

I am a US Navy Veteran who was trained to work in demanding operating environments where a vast array of technologies provide deep analytical insights to data. I have worked using my training in analytical skills in the military, as an airborne sensor operator and in civilian life as a technology officer.