WooCommerce Custom Order Data

WooCommerce Custom Order Data

If you are extending WooCommerce by creating themes or developing plugins you will find this plugin to be priceless!

WooCommerce uses WordPress logic and database tables to store data on store items, orders, checkouts… If you are integrating a payment gateway or any 3rd party app with your store, you sometimes need to store some extra data for specific orders. It tends to be very hard or even impossible to extend orders with custom data.

“WooCommerce Custom Order Data” plugin enables you to extend WC orders with practically any custom data by writing just one line of code and use it wherever you need.

Extending WC orders

Here’s how easy it is to extend a WooCommerce order in your code:


// extend order with custom data

WC_CustomOrderData::extend($order);

To set a custom property to an order, just type:


// set 'your_custom_property' to an order

$order->custom->your_custom_property = 'some value';

After that you can use your custom order property by referring the “custom” order property:


// get 'your_custom_property'

$custom_property = $order->custom->your_custom_property;

You can allways check if a custom order property exists using the standard PHP way:


// check if'your_custom_property' is set

if(isset($order->custom->your_custom_property)) {

// do stuff

}

All custom order properties are saved in a separate database table. When you finish working with the order, make sure you save custom data by typing:


// save all custom properties

$order->custom->save();

Note: Storred objects and arrays will be restored as arrays.

Download

You can download “WooCommerce Custom Order Data” plugin, leave feedback or ask for support on the plugin’s official page on WordPress.Org.

3 thoughts on “WooCommerce Custom Order Data

  1. Thank you, this looks pretty helpful. I’m designing a custom solution that stores customer data and I need it to attach to any order that needs that information.

    I will give this a try!

  2. Any chance for an update to this plugin for the latest version of WooCommerce? I see it’s throwing the following error message:

    id was called incorrectly. Order properties should not be accessed directly. Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), do_action(‘template_redirect’), WP_Hook->do_action, WP_Hook->apply_filters, WC_AJAX::do_wc_ajax, do_action(‘wc_ajax_checkout’), WP_Hook->do_action, WP_Hook->apply_filters, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, xxx->process_payment, xxx::createOrder, xxx::extend, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0.

    Thanks.

  3. Hello, is this plugin still compatible with the newest wordpress version (4.9.5), i need to set custom order data and yout plugin seems very useful?

    Thanks for your reply 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *