Abstract_WC_Order_Data_Store_CPT::update_post_meta()
Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.
Method of the class: Abstract_WC_Order_Data_Store_CPT{}
Hooks from the method
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->update_post_meta( $order );
- $order(WC_Order) (required) (passed by reference — &)
- Order object.
Changelog
Since 3.0.0 | Introduced. |
Abstract_WC_Order_Data_Store_CPT::update_post_meta() Abstract WC Order Data Store CPT::update post meta code WC 9.4.2
protected function update_post_meta( &$order ) { $updated_props = array(); $meta_key_to_props = array( '_order_currency' => 'currency', '_cart_discount' => 'discount_total', '_cart_discount_tax' => 'discount_tax', '_order_shipping' => 'shipping_total', '_order_shipping_tax' => 'shipping_tax', '_order_tax' => 'cart_tax', '_order_total' => 'total', '_order_version' => 'version', '_prices_include_tax' => 'prices_include_tax', ); $props_to_update = $this->get_props_to_update( $order, $meta_key_to_props ); foreach ( $props_to_update as $meta_key => $prop ) { $value = $order->{"get_$prop"}( 'edit' ); $value = is_string( $value ) ? wp_slash( $value ) : $value; if ( 'prices_include_tax' === $prop ) { $value = $value ? 'yes' : 'no'; } $updated = $this->update_or_delete_post_meta( $order, $meta_key, $value ); if ( $updated ) { $updated_props[] = $prop; } } /** * Action fired after updating order properties. * * @param WC_Abstract_Order $order Order object. * @param string[] $updated_props Array of updated properties. * * @since 2.7.0 */ do_action( 'woocommerce_order_object_updated_props', $order, $updated_props ); }