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.
Метод класса: WC_Order_Data_Store_CPT{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->update_order_meta_from_object( $order );
- $order(WC_Abstract_Order) (обязательный)
- Order object.
Код WC_Order_Data_Store_CPT::update_order_meta_from_object() WC Order Data Store CPT::update order meta from object WC 11.0.1
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 );
}
}
}