Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableDataStore::get_db_row_from_order
Produces an array with keys 'row' and 'format' that can be passed to $wpdb->update() as the $data and $format parameters. Values are taken from the order changes array and properly formatted for inclusion in the database.
Метод класса: OrdersTableDataStore{}
Хуков нет.
Возвращает
Массив.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_db_row_from_order( $order, $column_mapping, $only_changes );
- $order(WC_Abstract_Order) (обязательный)
- Order.
- $column_mapping(массив) (обязательный)
- Table column mapping.
- $only_changes(true|false)
- Whether to consider only changes in the order object or all fields.
По умолчанию: false
Список изменений
| С версии 6.8.0 | Введена. |
Код OrdersTableDataStore::get_db_row_from_order() OrdersTableDataStore::get db row from order WC 10.4.2
protected function get_db_row_from_order( $order, $column_mapping, $only_changes = false ) {
$changes = $only_changes ? $order->get_changes() : array_merge( $order->get_data(), $order->get_changes() );
// Make sure 'status' is correctly prefixed.
if ( array_key_exists( 'status', $column_mapping ) && array_key_exists( 'status', $changes ) ) {
$changes['status'] = $this->get_post_status( $order );
}
$row = array();
$row_format = array();
foreach ( $column_mapping as $column => $details ) {
if ( ! isset( $details['name'] ) || ! array_key_exists( $details['name'], $changes ) ) {
continue;
}
$row[ $column ] = $this->database_util->format_object_value_for_db( $changes[ $details['name'] ], $details['type'] );
$row_format[ $column ] = $this->database_util->get_wpdb_format_for_type( $details['type'] );
}
if ( ! $row ) {
return false;
}
return array(
'data' => $row,
'format' => $row_format,
);
}