Automattic\WooCommerce\Internal\DataStores\Orders
LegacyDataHandler::cleanup_post_data()
Performs a cleanup of post data for a given order and also converts the post to the placeholder type in the backup table.
Метод класса: LegacyDataHandler{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$LegacyDataHandler = new LegacyDataHandler(); $LegacyDataHandler->cleanup_post_data( $order_id, $skip_checks ): void;
- $order_id(int) (обязательный)
- Order ID.
- $skip_checks(true|false)
- Whether to skip the checks that happen before the order is cleaned up.
По умолчанию: false
Код LegacyDataHandler::cleanup_post_data() LegacyDataHandler::cleanup post data WC 9.7.1
public function cleanup_post_data( int $order_id, bool $skip_checks = false ): void { global $wpdb; $post_type = get_post_type( $order_id ); if ( ! in_array( $post_type, array_merge( wc_get_order_types( 'cot-migration' ), array( $this->data_synchronizer::PLACEHOLDER_ORDER_POST_TYPE ) ), true ) ) { // translators: %d is an order ID. throw new \Exception( esc_html( sprintf( __( '%d is not of a valid order type.', 'woocommerce' ), $order_id ) ) ); } $order_exists = $this->data_store->order_exists( $order_id ); if ( $order_exists ) { $order = wc_get_order( $order_id ); if ( ! $order ) { // translators: %d is an order ID. throw new \Exception( esc_html( sprintf( __( '%d is not a valid order ID.', 'woocommerce' ), $order_id ) ) ); } if ( ! $skip_checks && ! $this->is_order_newer_than_post( $order ) ) { // translators: %1 is an order ID. throw new \Exception( esc_html( sprintf( __( 'Data in posts table appears to be more recent than in HPOS tables. Compare order data with `wp wc hpos diff %1$d` and use `wp wc hpos backfill %1$d --from=posts --to=hpos` to fix.', 'woocommerce' ), $order_id ) ) ); } } $wpdb->delete( $wpdb->postmeta, array( 'post_id' => $order_id ), array( '%d' ) ); // Delete all metadata. if ( $order_exists ) { // wp_update_post() changes the post modified date, so we do this manually. // Also, we suspect using wp_update_post() could lead to integrations mistakenly updating the entity. $wpdb->update( $wpdb->posts, array( 'post_type' => $this->data_synchronizer::PLACEHOLDER_ORDER_POST_TYPE, 'post_status' => 'draft', ), array( 'ID' => $order_id ), array( '%s', '%s' ), array( '%d' ) ); } else { $wpdb->delete( $wpdb->posts, array( 'ID' => $order_id ), array( '%d' ) ); } clean_post_cache( $order_id ); }