Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::upshift_or_delete_child_orders()privateWC 1.0

Set the parent id of child orders to the parent order's parent if the post type for the order is hierarchical, just delete the child orders otherwise.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->upshift_or_delete_child_orders( $order ): void;
$order(\WC_Abstract_Order) (обязательный)
Order object.

Код OrdersTableDataStore::upshift_or_delete_child_orders() WC 9.3.3

private function upshift_or_delete_child_orders( $order ): void {
	global $wpdb;

	$order_table     = self::get_orders_table_name();
	$order_parent_id = $order->get_parent_id();

	if ( $this->legacy_proxy->call_function( 'is_post_type_hierarchical', $order->get_type() ) ) {
		$wpdb->update(
			$order_table,
			array( 'parent_order_id' => $order_parent_id ),
			array( 'parent_order_id' => $order->get_id() ),
			array( '%d' ),
			array( '%d' )
		);
	} else {
		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		$child_order_ids = $wpdb->get_col(
			$wpdb->prepare(
				"SELECT id FROM $order_table WHERE parent_order_id=%d",
				$order->get_id()
			)
		);
		// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared

		foreach ( $child_order_ids as $child_order_id ) {
			$child_order = wc_get_order( $child_order_id );
			if ( $child_order ) {
				$child_order->delete( true );
			}
		}
	}
}