Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::get_db_rows_for_order()
Generates an array of rows with all the details required to insert or update an order in the database.
Метод класса: OrdersTableDataStore{}
Хуки из метода
Возвращает
Массив
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_db_rows_for_order( $order, $context, $only_changes ): array;
- $order(\WC_Abstract_Order) (обязательный)
- The order.
- $context(строка)
- The context: 'create' or 'update'.
По умолчанию: 'create' - $only_changes(true|false)
- Whether to consider only changes in the order for generating the rows.
По умолчанию: false
Список изменений
С версии 6.8.0 | Введена. |
Код OrdersTableDataStore::get_db_rows_for_order() OrdersTableDataStore::get db rows for order WC 8.3.1
protected function get_db_rows_for_order( \WC_Abstract_Order $order, string $context = 'create', bool $only_changes = false ): array { $result = array(); $row = $this->get_db_row_from_order( $order, $this->order_column_mapping, $only_changes ); if ( 'create' === $context && ! $row ) { throw new \Exception( 'No data for new record.' ); // This shouldn't occur. } if ( $row ) { $result[] = array( 'table' => self::get_orders_table_name(), 'data' => array_merge( $row['data'], array( 'id' => $order->get_id(), 'type' => $order->get_type(), ) ), 'format' => array_merge( $row['format'], array( 'id' => '%d', 'type' => '%s', ) ), ); } // wc_order_operational_data. $row = $this->get_db_row_from_order( $order, $this->operational_data_column_mapping, $only_changes ); if ( $row ) { $result[] = array( 'table' => self::get_operational_data_table_name(), 'data' => array_merge( $row['data'], array( 'order_id' => $order->get_id() ) ), 'format' => array_merge( $row['format'], array( 'order_id' => '%d' ) ), ); } // wc_order_addresses. foreach ( array( 'billing', 'shipping' ) as $address_type ) { $row = $this->get_db_row_from_order( $order, $this->{$address_type . '_address_column_mapping'}, $only_changes ); if ( $row ) { $result[] = array( 'table' => self::get_addresses_table_name(), 'data' => array_merge( $row['data'], array( 'order_id' => $order->get_id(), 'address_type' => $address_type, ) ), 'format' => array_merge( $row['format'], array( 'order_id' => '%d', 'address_type' => '%s', ) ), ); } } /** * Allow third parties to include rows that need to be inserted/updated in custom tables when persisting an order. * * @since 6.8.0 * * @param array Array of rows to be inserted/updated when persisting an order. Each entry should be an array with * keys 'table', 'data' (the row), 'format' (row format), 'where' and 'where_format'. * @param \WC_Order The order object. * @param string The context of the operation: 'create' or 'update'. */ $ext_rows = apply_filters( 'woocommerce_orders_table_datastore_extra_db_rows_for_order', array(), $order, $context ); return array_merge( $result, $ext_rows ); }