Automattic\WooCommerce\Internal\DataStores\Orders

DataSynchronizer::handle_deleted_post()privateWC 1.0

Handle the deleted_post

When posts is authoritative and sync is enabled, deleting a post also deletes COT data.

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

Хуков нет.

Возвращает

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

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

// private - только в коде основоного (родительского) класса
$result = $this->handle_deleted_post( $postid, $post ): void;
$postid(int) (обязательный)
The post id.
$post(WP_Post) (обязательный)
The deleted post.

Код DataSynchronizer::handle_deleted_post() WC 8.6.1

private function handle_deleted_post( $postid, $post ): void {
	global $wpdb;

	$order_post_types = wc_get_order_types( 'cot-migration' );
	if ( ! in_array( $post->post_type, $order_post_types, true ) ) {
		return;
	}

	if ( ! $this->get_table_exists() ) {
		return;
	}

	if ( $this->data_sync_is_enabled() ) {
		$this->data_store->delete_order_data_from_custom_order_tables( $postid );
	} elseif ( $this->custom_orders_table_is_authoritative() ) {
		return;
	}

	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.SlowDBQuery
	if ( $wpdb->get_var(
		$wpdb->prepare(
			"SELECT EXISTS (SELECT id FROM {$this->data_store::get_orders_table_name()} WHERE ID=%d)
					AND NOT EXISTS (SELECT order_id FROM {$this->data_store::get_meta_table_name()} WHERE order_id=%d AND meta_key=%s AND meta_value=%s)",
			$postid,
			$postid,
			self::DELETED_RECORD_META_KEY,
			self::DELETED_FROM_POSTS_META_VALUE
		)
	)
	) {
		$wpdb->insert(
			$this->data_store::get_meta_table_name(),
			array(
				'order_id'   => $postid,
				'meta_key'   => self::DELETED_RECORD_META_KEY,
				'meta_value' => self::DELETED_FROM_POSTS_META_VALUE,
			)
		);
	}
	// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.SlowDBQuery
}