WC_Order_Data_Store_CPT::update_order_meta_from_object
Helper method to update order metadata from initialized order object. Overrides the parent method to add COGS sync support for compatibility mode.
Method of the class: WC_Order_Data_Store_CPT{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->update_order_meta_from_object( $order );
- $order(WC_Abstract_Order) (required)
- Order object.
WC_Order_Data_Store_CPT::update_order_meta_from_object() WC Order Data Store CPT::update order meta from object code WC 10.7.0
protected function update_order_meta_from_object( $order ) {
parent::update_order_meta_from_object( $order );
if ( ! $this->cogs_is_enabled() || ! $order->has_cogs() ) {
return;
}
$cogs_value = $order->get_cogs_total_value( 'edit' );
/**
* Filter to customize the Cost of Goods Sold value that gets saved for a given order,
* or to suppress the saving of the value (so that custom storage can be used).
*
* @since 9.5.0
*
* @param float|null $cogs_value The value to be written to the database. If returned as null, nothing will be written.
* @param WC_Abstract_Order $item The order for which the value is being saved.
*/
$cogs_value = apply_filters( 'woocommerce_save_order_cogs_value', $cogs_value, $order );
if ( ! is_null( $cogs_value ) ) {
if ( 0.0 === (float) $cogs_value ) {
delete_post_meta( $order->get_id(), '_cogs_total_value' );
} else {
update_post_meta( $order->get_id(), '_cogs_total_value', $cogs_value );
}
}
}