WC_Order_Data_Store_CPT::read_cogs_dataprivateWC 1.0

Read the Cost of Goods Sold value for a given order from the database, if available, and apply it to the order.

Method of the class: WC_Order_Data_Store_CPT{}

Hooks from the method

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->read_cogs_data( $order, $post_meta );
$order(WC_Order) (required)
The order to get the COGS value for.
$post_meta(array) (required)
The post meta data array.

WC_Order_Data_Store_CPT::read_cogs_data() code WC 10.5.0

private function read_cogs_data( $order, $post_meta ) {
	$cogs_value = isset( $post_meta['_cogs_total_value'][0] ) ? (float) $post_meta['_cogs_total_value'][0] : 0;

	/**
	 * Filter to customize the Cost of Goods Sold value that gets loaded for a given order.
	 *
	 * @since 9.5.0
	 *
	 * @param float              $cogs_value The value as read from the database.
	 * @param WC_Abstract_Order $order      The order for which the value is being loaded.
	 */
	$cogs_value = apply_filters( 'woocommerce_load_order_cogs_value', $cogs_value, $order );

	$order->set_cogs_total_value( (float) $cogs_value );
	$order->apply_changes();
}