Categories
Developer Resources

New @wordpress/data stores in WooCommerce Blocks

In WooCommerce blocks 8.7.0 we refactored a significant portion of our Cart and Checkout blocks’ code. Specifically, a lot of the data previously kept in React Contexts was moved into WordPress data stores (@wordpress/data). We did this to make it easier for third party extensions to extend the functionality of the Cart and Checkout blocks.

The changes we’ve made are all backward compatible, so any existing integrations should continue to work without any intervention.

We have added the following data stores, however, some actions and selectors on these stores are currently for internal use only while we evaluate which ones third party applications should have access to:

  • wc/store/payment – used to store information about the payment state and available payment methods.
  • wc/store/validation – used to store information about validation, currently this is used in by Cart block to ensure the Shipping Calculator form is valid, and by the Checkout block to ensure the checkout form is valid. Extensions can use this data store to add validation to their own integrations.
  • wc/store/checkout – used to store information about the checkout state (whether it’s before processing, after processing, idle, or completed), whether it has errors, or whether any calculations are pending (changes to shipping method or address will cause a “calculation” to be in progress until the request completes). It also stores whether the shipping address should be used as the billing address, the draft order number, and the order notes.

These stores are documented on GitHub. This documentation is continually being updated so please be sure to check back often.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.