Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::trash_order()publicWC 1.0

Trashes an order.

Метод класса: OrdersTableDataStore{}

No Hooks.

Return

null. Nothing.

Usage

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->trash_order( $order );
$order(WC_Order) (required)
The order object

Code of OrdersTableDataStore::trash_order() WC 7.1.0

public function trash_order( $order ) {
	global $wpdb;

	if ( 'trash' === $order->get_status( 'edit' ) ) {
		return;
	}

	$trash_metadata = array(
		'_wp_trash_meta_status' => 'wc-' . $order->get_status( 'edit' ),
		'_wp_trash_meta_time'   => time(),
	);

	foreach ( $trash_metadata as $meta_key => $meta_value ) {
		$this->add_meta(
			$order,
			(object) array(
				'key'   => $meta_key,
				'value' => $meta_value,
			)
		);
	}

	$wpdb->update(
		self::get_orders_table_name(),
		array(
			'status'           => 'trash',
			'date_updated_gmt' => current_time( 'Y-m-d H:i:s', true ),
		),
		array( 'id' => $order->get_id() ),
		array( '%s', '%s' ),
		array( '%d' )
	);

	$order->set_status( 'trash' );

	$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
	if ( $data_synchronizer->data_sync_is_enabled() ) {
		wp_trash_post( $order->get_id() );
	}
}