Automattic\WooCommerce\Admin\API\Reports\Orders\Stats

DataStore::update()public staticWC 1.0

Update the database with stats data.

{} Это метод класса: DataStore{}

Возвращает

int|true|false. Returns -1 if order won't be processed, or a boolean indicating processing success.

Использование

$result = DataStore::update( $order );
$order(WC_Order|WC_Order_Refund) (обязательный)
Order or refund to update row for.

Код DataStore::update() WC 6.6.1

public static function update( $order ) {
	global $wpdb;
	$table_name = self::get_db_table_name();

	if ( ! $order->get_id() || ! $order->get_date_created() ) {
		return -1;
	}

	/**
	 * Filters order stats data.
	 *
	 * @param array $data Data written to order stats lookup table.
	 * @param WC_Order $order  Order object.
	 */
	$data = apply_filters(
		'woocommerce_analytics_update_order_stats_data',
		array(
			'order_id'           => $order->get_id(),
			'parent_id'          => $order->get_parent_id(),
			'date_created'       => $order->get_date_created()->date( 'Y-m-d H:i:s' ),
			'date_created_gmt'   => gmdate( 'Y-m-d H:i:s', $order->get_date_created()->getTimestamp() ),
			'num_items_sold'     => self::get_num_items_sold( $order ),
			'total_sales'        => $order->get_total(),
			'tax_total'          => $order->get_total_tax(),
			'shipping_total'     => $order->get_shipping_total(),
			'net_total'          => self::get_net_total( $order ),
			'status'             => self::normalize_order_status( $order->get_status() ),
			'customer_id'        => $order->get_report_customer_id(),
			'returning_customer' => $order->is_returning_customer(),
		),
		$order
	);

	$format = array(
		'%d',
		'%d',
		'%s',
		'%s',
		'%d',
		'%f',
		'%f',
		'%f',
		'%f',
		'%s',
		'%d',
		'%d',
	);

	if ( 'shop_order_refund' === $order->get_type() ) {
		$parent_order = wc_get_order( $order->get_parent_id() );
		if ( $parent_order ) {
			$data['parent_id'] = $parent_order->get_id();
			$data['status']    = self::normalize_order_status( $parent_order->get_status() );
		}
	}

	// Update or add the information to the DB.
	$result = $wpdb->replace( $table_name, $data, $format );

	/**
	 * Fires when order's stats reports are updated.
	 *
	 * @param int $order_id Order ID.
	 */
	do_action( 'woocommerce_analytics_update_order_stats', $order->get_id() );

	// Check the rows affected for success. Using REPLACE can affect 2 rows if the row already exists.
	return ( 1 === $result || 2 === $result );
}