Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::read_cogs_data()privateWC 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: OrdersTableDataStore{}

Hooks from the method

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->read_cogs_data( $order );
$order(\WC_Abstract_Order) (required)
The order to get the COGS value for.

OrdersTableDataStore::read_cogs_data() code WC 9.6.0

private function read_cogs_data( WC_Abstract_Order $order ) {
	$meta_entry = $this->data_store_meta->get_metadata_by_key( $order, '_cogs_total_value' );
	$cogs_value = false === $meta_entry ? 0 : (float) current( $meta_entry )->meta_value;

	/**
	 * 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 $product 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();
}