By now most if not all of you will have heard of the considerable changes to WooCommerce in 3.0 and beyond. I mean pretty much every major version bump in WC history has had some pretty major changes, but for me this was the most major of all, not least because of how major it may become.

To explain, one of the biggest things about WooCommerce 3.0 is the inclusion of the new CRUD mechanisms, to those who don’t know that anagram it means Create Read Update Delete. In WooCommerce 3.0 all objects including orders have new methods like WC_Order::save() and such like. The idea is to make the methods developers use to save and update data attached to these objects, the eventual plan to possibly move away from custom post types and post_meta entirely but that is another blog post.

For now, as far as I know most of the old ways of updating order data still work, but to get ahead of the curve you should start to use the new mechanisms, you can even wrap them in version_compare conditionals for backwards compatibility of course.

For anyone who reads this and wonders how to get the same data here you go:

PHP

1

2

3

4

5

6

7

if(version_compare(WC()->version,'3.0.0','>=')){

$ex_one=$order->get_meta('_example_key',true);

$ex_two=$order->get_meta('_example_other_key',true);

}else{

$ex_one=get_post_meta($order->id,'_example_key',true);

$ex_two=get_post_meta($order->id,'_example_other_key',true);

}

Like the code you see here? You can hire me at Codeable.io - a WordPress specialist outsourcing site that vets developers to make sure they are of the highest standard. See all developers you can hire through Codeable here.