Today we’re excited to release WooCommerce 3.0 (previously 2.7), dubbed the “Bionic Butterfly”, into the wild! 3.0 has been in beta since December, development since August, and has had over 3000 commits from 115 contributors.
Read on to find out what’s new!
CRUD (Create, Read, Update, Delete) objects and data-stores
The CRUD classes in 3.0 represent a fundamental change in how we work with data objects in core (thats products, orders, coupons, customers etc).
Traditionally in WordPress when working with, for example, posts and post data you’re pretty much able to update/get/create any meta data you want anyway you want, procedurally direct to the database. Our new CRUD approach on the other hand introduces another layer between the database and your code which adds structure, validation and control.
As a simple example, let’s imagine you have a product and this product has a price. With the old way, if you wanted to update the price of this product you’d:
- need to know where that price is stored (meta key)
- need to know in what format that data is stored (string? 2 decimal places?)
- need to know how to update that data (
update_post_meta
).
With CRUD, you instead have a list of product properties, one of which is price, and you can call ->set_regular_price()
to set the data, followed by ->save()
to make that data persist in the database. Where is gets stored is none of your concern and formatting is handled for you. Example:
$product = wc_get_product( 1 ); $product->set_regular_price( 10.99 ); $product->save();
The benefits?
- We define the structured data for each resource and you can look it up easily.
- We control the flow of data, and any validation needed.
- You don’t need to know the internals of the data you’re working with.
- Internally, the data can be moved elsewhere e.g. custom tables, without affecting existing code.
- It’s reusable (API, CLI, WP Admin) and has more unit test coverage.
We’re excited about this change, and it really paves the way for us to improve performance in the future.
You can read more about the new CRUD classes here.
A new product gallery
Back in August we posted about some improvements we wanted to make to our product image galleries and then took a poll to see what users wanted. The results showed that the majority of voters liked the zoom feature, and a significant number of people wanted to keep some form of lightbox.
Based on these findings, we devised a system that included both, with added mobile device support and includes the following benefits:
- Visitors now have access to both magnification and zooming (lightbox)
- Gallery behaviour is more intuitive – clicking a thumbnail updates the main image rather than opening a lightbox
- Dramatic improvements on handheld, in particular; touch gestures – swipe to scroll through the gallery, pinch to zoom, swipe up to close, etc
- Opening the lightbox on mobile now displays the image in it’s true size, larger than the in-page display
To avoid disrupting custom lightboxes in themes, non-default WordPress themes will need to enable the new functionality using add_theme_support()
. It’s easy; you can read how to do this here.
New CLI (Command Line Interface) and Rest API v2
2.6.x had a CLI but it was custom and didn’t share any code with the rest of the codebase. This was wasteful and hard to maintain; we have a fully blown REST API after all. In 3.0.x we’ve made a new CLI which integrates directly with the REST API and supports all of the same functionality.
You can read more about the new CLI here.
We’ve also introduced a new version of the API with several benefits over v1. To summarise whats new:
- Support for meta data on most endpoints.
- New variations endpoint for creating and updating variations. In addition, we’ve prevented the (broken) ability to manipulate variations directly on the products endpoints.
- Settings endpoint (update/view shop settings).
- Shipping zones endpoints.
- Payment and shipping methods endpoints, including settings.
- Added support for oAuth1.0a authentication using headers.
- Additional caching and removal of slow queries (last order query from the customers part of the API).
You can view the REST API documentation here.
A new logging system

The new logger, which can be used by extensions to log events, errors and warnings, addresses limitations in our old logger. It includes log handlers, it implements the methods described by the PSR-3 logger interface, and it’s much more extensible.
The new logger includes 2 handlers; file and database. The database handler can be enabled with;
define( 'WC_LOG_HANDLER', 'WC_Log_Handler_DB' );
Read more about the improved logging system here
Performance improvements
There are several performance improvements in 3.0.x. To summarise the main ones:
- For variable products specifically, we’ve tried to optimise variable product sync. Upper/lower price meta data is no longer stored (it was not used in core), just the main prices, if a child has weight, and if a child has dimensions.
- In our template files, we’ve removed WP_Query from up-sells.php and related.php and replaced with PHP foreach loop (since we already have the product IDs). This means one less large query on product and cart pages.
- We’ve removed the feature where old orders get access to new downloads on product edit. Looping (potentially) thousands of orders to do this update was too much of a performance burden for some stores and this also could lead to unexpected behaviour. After this update we do however update edited downloads, so editing a file will not prevent purchasers from downloading it.
- We’ve removed the ‘order items’ column on the orders page. Whilst this can be useful, loading all items for all orders on the page is not performant. This may return in the future but it will need to be dynamic so it may just be left for a future UI redesign.
- Rather than sending emails in one big request when placing an order on checkout, we’ve implemented a delayed CRON event to send the emails instead. This sends the emails after a small delay in a separate request and in turns speeds up the checkout by about 50% in testing.
Additionally, since joining to the post meta table can cause significant slowdown when you have a large product catalog, we’ve made some optimisations to utilise taxonomies more for frontend product filters.
- Product visibility (which controls if products are visible in the catalog, search, or both) was previously post meta, and was used in all WooCommerce product queries. In 3.0 this is a new product_visibility taxonomy instead. In testing, with ~8k products we saw speed improvements of around 94%.
- Featured products are also using the new product_visibility taxonomy instead of meta which improves queries on those.
- And the same for out of stock products. If you’re hiding out of stock products from your catalog, you’ll see improvements.
Meta to taxonomy conversions are handled by our upgrade script.
Everything else
- Sorting tax rates was previously a manual process. When you have pages of tax rates this becomes cumbersome. In 3.0.x we sort tax rates automatically, placing more specific rules above more general rules (the way they should be sorted).
- On the frontend, we’ve made the storewide notice dismissible making it less of an issue when it overlaps content on mobile 🙂
- On WordPress networks/multisite, when a user logs into a store with an account, but not an account on the current store, WooCommerce will add existing users to the store rather than throw an error as it did in 2.6.
- Previously, structured data was output inline in our template files (marking up things such as products). In 3.0 we’ve switched to JSON-LD format which keeps our template files tidy and keeps data intact if customisations are made by theme developers.
- When authorising payments with PayPal Standard, funds are now automatically captured when the order is changed to processing or completed. It was a manual process in 2.6.x.
- We merged cart percent and product percent coupon types into one and removed product_cart discounts. The discounts these coupons provide are identical, however, the cart based validation would stop the coupon being applied if any non-eligble item was in the cart, rather than just discounting eligible items like product coupons do. This was not intuitive, caused store owner and confusion, and most important of all, just meant users would have to checkout twice to make use of these coupons (thats not fair nor ideal).
- Variable product prices which contain sale items will no longer contain a strikethrough. Showing a striked out range followed by a non-striked out range, especially if the prices overlap, is too darn confusing and longwinded. Instead we show just a range now. Sale prices will still be shown when selecting a variation.
- Grouped products are linked from the parent rather than the children. Children can be in more than one group.
There are many more smaller tweaks and improvements in 3.0 but this covers the main changes that you may notice.
Upgrading to 3.0
As always, before upgrading ensure that your extensions and theme are compatible with 3.0 and you’ve made backups. If unsure, check with the theme/extension developer.
Store owners, read this helpful guide on preparing for the update and if you see any deprecation notices after updating don’t be alarmed; read here to understand why.
After upgrading, the data upgrader prompt will run updates in the background. If your site is not accessible or password protected there may be a delay for the cron-based fallback to run.
If you’ve not yet made your extensions and themes compatible with 3.0.x (!) here are some notes we’ve been writing during our own testing:
- 2.6.x to 3.0.0 Developer Migration Notes
- Template changes
- Deprecated functions and filters
- Bookings extension compatibility example
- Deposits extension compatibility example
- More extension compatibility examples
How we tested 3.0
In total we had 4 beta versions for “2.7” from December; you can check out the Beta 1, beta 2, and beta 3 posts if interested. We then had a “2.7” release candidate before deciding to move to Semantic Versioning and use 3.0.0
instead. In total our betas have had at least 1,148 downloads according to the stats we have from Github.
Internally we’ve been testing our own plugins and themes, releasing updates where needed, and we’ve had support from our 3rd party developers also. Huge kudos to our 3rd party devs!
On top of the manual testing we’ve all been performing, and the testing by the community, we’ve also been gradually expanding our unit test coverage which is now up to 50%. You can view current test coverage on Scruitinizer.
A huge thanks for our contributors!
A massive thanks to everyone in the community who have contributed, be that via issue reports, fixes, translation, testing, supporting other users or simply spreading the word!
mikejolley | claudiosanches | justinshreve | sirreal | aristath | franticpsyx |
jameskoster | thenbrent | ramiy | opportus | corsonr | WPprodigy |
claudiulodro | shivapoudel | JeroenSormani | bor0 | leewillis77 | rynaldos |
jobthomas | Chouby | maximus80 | gedex | rellect | jtsternberg |
Dartui | danielhuesken | ryanr14 | belcherj | prettyboymp | pierrebuet |
vishalkakadiya | helgatheviking | terence1990 | nishitlangaliya | bekarice | dwainm |
todeveni | mattyza | coderkevin | rasmusbe | rodrigoprimo | davefx |
tlovett1 | proArtex | akashsonic | jaydeeprami | maciekkus | jamesckemp |
kahanit | sabbir1991 | AnwerAR | ragulka | attiladonath | nicomollet |
kouratoras | ttarpinyan | MA7 | andreagrillo | A5hleyRich | webmandesign |
crodas | javorszky | Ramoonus | mik-laj | tiagonoronha | alarocca130 |
Sidsector9 | kalenjohnson | leogermani | datafeedr | DavidAnderson684 | davidlawson |
unfulvio | michaeltieso | MichelPoulain | dabernathy89 | bobbingwide | flemarie |
hussong | ChuckMac | hannahswain | nabsul | justinstern | renemeye |
DanielAGW | zachd | desko27 | hereswhatidid | roykho | mattallan |
bryceadams | daigo75 | mkdgs | niravmehta | lucasstark | BFTrick |
faisal-alvi | duracelltomi | jluisfreitas | macbookandrew | iMazed | matheusgimenez |
flyonthenet | jezmck | fuzzguard | widoz | BIOSTALL | slash1andy |
ChaseWiseman | iconicwp | ksere | divadmts | pmaiorana | thii |
shoheitanaka |
Thanks for sharing, some great updates in there 🙂 Especially pleased with the JSON-LD update after I had to manually remove the on-page markup from another site before >.<
LikeLike
Hey, Congrats for 3.0.
but since i as update WC 3.0, my page is always refreshing !
Check here :
http://www.jiefsourd.eu/wp (is a fake Shop, i’m studying WebDesign)
LikeLiked by 1 person
Not sure if it’s 3, but you do have the ‘geolocation with page cache’ setting enabled – thats why you have the v= string in the URL 🙂
LikeLiked by 3 people
Is solved ! Thanx you 🙂
LikeLiked by 1 person
Hi – I too have the page refreshing issue since upgrading to 3.0 (and yes, I use geolocation with caching support). Is there a fix, other than to disable this setting?
Thanks!
LikeLike
No but keep an eye on the Github issue.
LikeLiked by 1 person
Hello,
Please help! How do I disable geolocation? Upated to WC 3.0 and the page and site is constantly refreshing?
Appreciate any advice.
LikeLike
This is fixed in 3.0.1
LikeLike
Is there no longer an automatic way to show the original price (with a strikethrough) and discounted price for a variable product?
LikeLike
Only for regular/simple products. When you’re showing ranges of prices it can be extremely confusing depending on your min/max before sale, and min/max after sale. You will however still see the striked out prices when you’ve selected a specific variation so you can see what sale is going on.
LikeLike
Cami, I have a “simple product” with sales prices and it isn’t doing a strikethrough either. Is this what you are seeing as well for your simple products?
LikeLike
Hello, I’m having some issues with the latest update (RC.1 is works). Functions: is_product(), is_cart(), wc_get_attribute_taxonomies() are all coming back as undefined. Was there a change in how WooCommerce initializes with wordpress or are these functions depreciated?
LikeLike
If these are undefined, WC is not active. Check your plugins section. The update/update may not be complete.
LikeLike
Hey mike, how do I replace the new version with the old one without messing up our store?
LikeLike
Restore a backup (you backed up right?) or update the old version from github to wp-content/plugins using FTP. Ensure the directory name is “woocommerce”.
LikeLike
ok and it appears to have autoupdated which was very frustrating. Is that a setting that I didn’t see to turn off by any chance? Thanks for the quick response. We have customers waiting to checkout literally as we speak.
Also just so im clear. I just drag and drop replace the woocommerce folder over the old one using zip file for version 2.7 right? (in FTP)
LikeLike
Using the file for 2.6.14 which was the last stable release.
WC/plugins cannot auto-update. It requires a click from an admin on the plugins screen.
LikeLike
it looks like only the source code is available for 2.6.14 – where other than github can i get the zip folder with files for 2.6.14?
and thats odd because im the only admin and I am honestly 1,110% positive I didn’t click update, so maybe its something else? wordpress update?
LikeLike
Github is the only place since the .org redesign. Nothing else can auto-update it I know of.
LikeLike
also, this won’t overwrite my settings will it?
LikeLike
No. As long as you never ‘uninstall’ from admin, you’re safe.
LikeLike
@Mike and @powerus92 , atm it’s still available here:
https://de.wordpress.org/plugins/woocommerce/advanced/
At the bottom you will find the older versions
LikeLike
It’s definitely showing that Woocommerce is up-to-date and active – thoughts? I’m not sure what would stop Woo from initializing
LikeLike
Maybe it failed to upload all files? Re-upload the plugin.
LikeLike
Woo! That worked – I had to download the master from Gitgub and update by manual upload. Thanks so much!
I’m also having an issue were the [featured products] shortcode returns nothing, but I think that may be my own custom code – thanks again!
LikeLike
Congrat WooCommerce team on this major release.
LikeLike
Hi, my domain is wezshop.com and I am facing this error which now my site blocked, can someone help me pls ? Thanks a dozen.
Fatal error: Class ‘WC_Legacy_API’ not found in /home4/wezshop/public_html/wp-content/plugins/woocommerce/includes/class-wc-api.php on line 17
LikeLike
I don’t think your plugin has finished or completed updating – you have missing files. Wait for it to finish updating, or upload the latest version manually via FTP.
LikeLike
Congrats to the entire Woo team on shipping 3.0.
Gotta say, the new gallery is brilliantly executed – well done one and all!
LikeLiked by 3 people
Congrats to the entire Woo team on shipping 3.0.
LikeLiked by 1 person
Congrats, on the update! Looks like a huge improvement. My clients are going to be happy.
LikeLike
Congrats and thank you ! Small issue on my side, when I’m in Orders panel, I can no longer see what the customers has ordered without clicking on it and opening a new window everytime. Any way I could still see what they ordered on the Orders page directly?
LikeLike
We took this out because it was a major performance bottleneck. If it did return in the future, it would have to be pulled in dynamically.
LikeLike
Thank you for the quick answer, makes sense. Still having a problem though, I’m selling stuff with variations like Small, Medium, etc. If I click the order since the update, the product is now along the lines of : Variation ID: 36914 instead of let’s say Small and it is quite a pain to find out which variation id number is which variation.
LikeLike
Are they fine in the cart? The ‘small’ should appear as part of the product name.
LikeLike
Yes, fine in the cart, actually the new orders coming in are now fine when I click on em. I have about 25 orders processing that ”lost” the ‘small’ and just have variation Id, no biggie I’ll find what is what manually. At least I can see the variation with the new orders.
LikeLike
Thanks for this shiny new version. Remarks: pagination does not show n-m but just first number on that page (mentioned before by me). New: the shortcode to show a number of products does not randomize anymore (orderby=”rand”).
Best regards, Egbert Jan, NL
LikeLike
Could not replicate those.
LikeLike
Nice one and congrats! Any idea when the new discount/coupon API is coming our way (#13325)? Very excited about that too…
LikeLike
Not yet 🙂 Possibly 4.0. We have a few minor releases to get out first.
LikeLike
Hi Mike
Until then, what would be the most elegant way to apply a “buy one get one free” type discount – by manipulating the cart object or the coupon object?
LikeLike
Coupons I think would be cleanest.
LikeLike
3.0 breaks all my permalinks. Changed the theme, same thing.
LikeLike
Settings > Permalinks > Save usually does the trick. Possibly translation related.
LikeLike
I tried saving permalinks, renaming htaccess, etc. no luck. What do you mean translation related?
LikeLike
If it was translated before it may have changed. No other reports of this yet. Try default permalink config? Post on support forum too – comments are not ideal.
LikeLike
Thanks! Permalinks fixed it for me.
LikeLike
Great work Mike, Claudio & the rest of the WC team + all the contributors to 3.0. WooCommerce 3.0 is as solid a release as I can remember – really great how the team stepped up to the testing challenge!
LikeLiked by 1 person
Really odd one for you. Just updated our sandbox site to 3.0. All seems ok but our test product page, which has variations, is now coming up blank. our test simple product page is fine and if we create a new variable product, it’s fine too.
Here’s the page: https://www.eleven.cc/sandbox/shop/test-product-page/
vs this simple product:
https://www.eleven.cc/sandbox/shop/atelier-derailleur/
So something’s happened, at least with us, to the product page with variations… any idea? We’ve stripped out everything and the page still comes up blank, so it’s nothing on the page itself…
LikeLike
…and here’s a V3 variable product (created after the update), which content wise is exactly the same as the pre-existing variable product liked above: https://www.eleven.cc/sandbox/shop/3-0-test/
LikeLike
Since this is an error 500, you need to either look at the server error logs or enable WP_DEBUG to see the error thats occurring.
LikeLike
Brilliant! Thank you. All sorted now – and a relief to know it was not Woo!
LikeLike
I just upgraded to woocommerce 3.0.0 on my wordpress site and it basically broke my store. Rewinded to 2.7 and everything is fine.
The three bugs I found are.
1. Product thumbnails are gone on product details page.
2. My product is a digital download that can have a few links to download. Generally one is text instructions and the other two are the product and product adds on both in zip form. When the customer purchases all download links download the same item the text instructions.
3. An order email is not sent.
LikeLike
See https://wordpress.org/support/topic/3-0-missing-gallery-functionality/ and https://github.com/woocommerce/woocommerce/issues/13923.
LikeLike
The first 3 links do not work –
2.6.x to 3.0.0 Developer Migration Notes
Template changes
Deprecated functions and filters
LikeLike
Fixed them up.
LikeLike
Hey Mike, would you mind clarifying the delayed CRON event for sending emails? How much of a delay, if noticeable at all, are we looking at?
LikeLike
Next request if CRON is working correctly. it’s queued 10 seconds into the future.
LikeLike
For “Variable” Product and at Stock Level I enable buy 1 unit only, found that the quantity combo still appear open to adjust over the product page on shop front-end. I suppose it should be invisible, or at least disable to adjust quantity. Pls help with thanks!
LikeLike
The logic for hiding this is in the quantity.php template file. Your theme may have a custom version of this. Users will still only be able to purchase one so it won’t affect orders.
LikeLike
Found that it still allow to me to checkout even I have added the quantity. The payment amount exactly the total quantity price. Previous version will block me from doing so…
Pls help.
LikeLike
Sounds like a plugin conflict to be honest. Validation in core appears to be working.
LikeLike
This update totally broke my sites D:
LikeLike
Post on the forums and we’ll try to help. You should definitely check everything on your site is compatible though as the post states above.
LikeLike
I went back to the the previous stable version instead. This update’s features sound very promising, but I’ll probably wait for a couple weeks more.
LikeLike
Hi, I am facing this error which now my site blocked, can someone help me pls ? Thanks a dozen. Not sure what’s wrong here.
Fatal error: Class ‘WC_Legacy_API’ not found in /home4/wezshop/public_html/wp-content/plugins/woocommerce/includes/class-wc-api.php on line 17
LikeLike
Sounds like the update has not fully completed – that file definitely exists. Reupload WooCommerce plugin to wp-content/plugins using FTP.
LikeLike
Hi, Thanks for the 3.0 upgrade! One thing I noticed is that it automatically adds product image to the product gallery. I used to have 3 thumbnails under the main image, now is four. Is there a way to prevent that from happening? Sometimes that product image has different dimensions and it looks awkward: example – https://designsbyrudy.com/product/dr-cb1-contemporary-concrete-bench/
Thank you,
Darek
LikeLike
It’s required for the slider so you can get back to the main image. Enable thumbnail cropping?
LikeLiked by 1 person
You have changed some of the post meta to taxonomies. So is faster to use taxonomies for true/false operations instead of post meta?
LikeLike
Querying products is faster via WP_Query.
LikeLiked by 1 person
Thank you Mike!
LikeLike
Thanks to Mike for helping us by being an inspiration for us to contribute. Thanks to @multidots for making me realise that YES I CAN DO…! 🙂
LikeLike
First of all, congratulations. I updated yesterday and the module of Woocommerce Booking appears a warning.
Warning: Declaration of WC_Product_Booking::get_price() should be compatible with WC_Product::get_price($context = ‘view’)
I have seen that in previous updates you have talked about this same problem. is it important to resolve? Or will it be resolved in future module updates?
Regards,
LikeLike
An update is coming, but you can ignore notices and warnings. See https://github.com/woocommerce/woocommerce/wiki/Deprecation-in-core#warnings-in-production-store-owners-read-this
LikeLiked by 1 person
Just one question. Is it possible to change the parameters of the Flexslider slider? If so, how? I’d like to show the left and right arrows.
LikeLike
There is a filter https://github.com/woocommerce/woocommerce/blob/71d0702523bcc365403dd3b84b945da5218d88b4/includes/class-wc-frontend-scripts.php#L467
LikeLike
Thanks!
LikeLike
Just one more question. Is it possible to convert the default thumbnail navigation to a dot one, just like the one here:
http://flexslider.woothemes.com/
If so, I suppose I have to edit the product-thumbnails.php template. Or hook the woocommerce_single_product_image_thumbnail_html filter. Am I wrong?
LikeLike
I’ve not tried this – let us know how you get on 🙂
LikeLike
Hello Mike.
I have local e-commerce website with Shopkeeper + WooCommerce
This morning I updated to 3.0 and the mobile version stopped working properly.
The menu was not responding for my Samsung galaxy S5 + Note 4. On Huawei it was ok…
However I reversed to previous version and It got better(menu got back to working, but on homepage the caret icon was gone)…
I was able to locate the problem: YITH WooCommerce Wishlist – when I disable it everything seemed to work fine… I will update it again to 3.0 tonight, because now is primetime in Bulgaria and I dont want to loose customers testing..
However, there is a compatibility issue with the Wishlist Plugin.
Best Regards, Deo
LikeLike
Is it their latest version, and have they been informed?
LikeLike
I didn’t need to touch any template.
function my_single_product_carousel_options( $array ) {
$array[‘controlNav’] = true;
return $array;
}
add_filter( ‘woocommerce_single_product_carousel_options’, ‘my_single_product_carousel_options’ );
Regards
LikeLike
Thanks for the update, excited to see where woocommerce goes from here, although I think I will hold off upgrading for a few weeks so plugin devs can catch up and any bugs can be resolved 🙂
LikeLike
I have not informed them so far. I have their latest version + their last release is 2 days ago…
Tonight(after 11hours – now is 4PM here) I will do some QA and can provide screenshots of the behavior(incompatibility).
LikeLike
well done folks! 🙂 Appreciate the changes made to WooCommerce
LikeLike
I am having issues when I send a customer an invoice. The link returns the Pay for Order page, but shows “Invalid order” error. I checked the system status, all of my templates are up to date and it does not look like the checkout/form-pay.php file was changed. Can anyone verify this is an issue with v3.0?
LikeLike
Can you log on Github so we can check? Need more details.
LikeLike
So I made some progress with this… It looks like the user has to be logged in to pay for their order. Which makes sense because the shortcode is “if ( ! current_user_can( ‘pay_for_order’, $order_id ) ) { echo ” . __( ‘Invalid order. If you have an account please log in and try again.’, ‘woocommerce’ ) . ‘ ‘ . __( ‘My account’, ‘woocommerce’ ) . ‘‘ . ”; return; }”.
I do find it interesting that it just started working with the v3.0 update. I found out that if I load my customer and their address information, then remove the customer (so it defaults back to guest), the link works without logging in (as it did pre v3.0).
LikeLike
Do we know if there are any workarounds to the “Invalid order. If you have an account please log in and try again” so that customers don’t have to be logged in to our site to pay for their order?
LikeLike
I don’t think that one is a bug. If the order is for a user, they need to be logged in otherwise it would leak a users address.
LikeLike
Gotcha – makes sense. Thank you!
LikeLike
Yes it does make sense.
But,
Since i’m not using any address for the customers anyway, is there a way to make it optional?
I would still very much like my customers to be able to pay simple and fast without having to log in like in the 2.x versions.
LikeLike
If you have no need for accounts you can use guest orders – no need to assign an order to a user.
LikeLike
I use it all in a slightly different way.
I have many cases where I create the orders for existing users. Like a point of sale setup.
For payment, those customers receive an email with a link.
I was able to customise it all according to my workflow, except for this change since 3.0. There are no hooks available, nor did I find a way to give users the capability to pay for orders without logging in.
Is there a way to make a request to include a filter? In class-wc-shortcode-checkout.php @line 90 `! current_user_can( ‘pay_for_order’, $order_id )`
LikeLiked by 1 person
I will answer my own question 😉
Use the user_has_cap filter.
https://codex.wordpress.org/Plugin_API/Filter_Reference/user_has_cap
LikeLiked by 1 person
@robbie7979 How to apply a solution?
LikeLike
Be careful when changing capabilities..
But to get you started, add this to your functions.php
“`/**
* customer_cap_filter()
*
* Filter on the current_user_can() function.
* This function is used to explicitly allow customers to pay for their own orders
* without the need to login.
*
* @param array $allcaps All the capabilities of the user
* @param array $cap [0] Required capability
* @param array $args [0] Requested capability
* [1] User ID
* [2] Associated object ID
*/
function customer_cap_filter( $allcaps, $cap, $args ) {
// Bail out if we’re not asking about an order:
if ( ‘pay_for_order’ != $args[0] )
return $allcaps;
// Load the order data:
$order = wc_get_order( $args[2] );
// Bail out if the user is the order author:
if ( $args[1] == $order->get_user_id() )
return $allcaps;
// Bail out if the order isn’t pending:
if ( ‘pending’ != $order->status )
return $allcaps;
// $allcaps[$cap[0]] = true;
$allcaps[‘pay_for_order’] = true;
return $allcaps;
}
add_filter( ‘user_has_cap’, ‘customer_cap_filter’, 10, 3 );“`
LikeLiked by 1 person