A few key concepts are at the base of all WC_Data objects. Understanding how the class getsIn “getter” methods, manipulatesWith “setter” methods and stores dataWith “update” methods can provide insights into how you can set various classes to interact with custom data involved in your project. In this section we’ll look at:
WC_Order_Item $data
WC_Order_Item $extra_data
The $data property is used to hold information that is fundamental to the representation of the class family. The $extra_data propertyPrimarily used by the product, order_item, and payment token families is used by descendants of the family to add data without overwriting the $data settings.
The WC_Meta_Data class helps ensure that WC_Data’s save_meta_data() method does not perform any unnecessary database writes.
__construct | __sleep | __wakeup | __clone | get_data_store |
delete | save | __toString | get_data | get_data_keys |
filter_null_meta* | get_meta_data | is_internal_meta_key* | get_meta | meta_exists |
add_meta_data | update_meta_data | delete_meta_data | delete_meta_data_by_mid | maybe_read_meta_data* |
save_meta_data | set_id | set_defaults | set_object_read | get_object_read |
set_prop* | get_changes | apply_changes | get_hook_prefix | get_prop* |
error* | get_id | set_date_prop* | set_props | read_meta_data |
read_meta_data | set_meta_data | get_extra_data_keys |
* method is protected (only available when writing methods within descendants of WC_Data)
Now that you understand the difference between the different data types, and understand the methods at the core of WC_Data functionality, you can start to see the opportunities for easy customization.
In the next topic, we’ll look at how Data Stores are used provide a flexible method of database storage for WC_Data objects
But first, check your knowledge.
Hint: Be sure to look in blue boxes and at purple text “tooltips” for notes while you take the quiz.
0 of 4 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 4 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Which data type has a special class to ensure database writes are minimized?
(T/F) WC_Data uses of a lot of “magic” methods.
Getters are…
Setters…