WC_Post_Data::delete_post()public staticWC 1.0

Removes variations etc belonging to a deleted post, and clears transients.

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

Хуков нет.

Возвращает

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

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

$result = WC_Post_Data::delete_post( $id );
$id(разное) (обязательный)
ID of post being deleted.

Код WC_Post_Data::delete_post() WC 8.7.0

public static function delete_post( $id ) {
	$container = wc_get_container();
	if ( ! $container->get( LegacyProxy::class )->call_function( 'current_user_can', 'delete_posts' ) || ! $id ) {
		return;
	}

	$post_type = self::get_post_type( $id );
	switch ( $post_type ) {
		case 'product':
			$data_store = WC_Data_Store::load( 'product-variable' );
			$data_store->delete_variations( $id, true );
			$data_store->delete_from_lookup_table( $id, 'wc_product_meta_lookup' );
			$container->get( ProductAttributesLookupDataStore::class )->on_product_deleted( $id );

			$parent_id = wp_get_post_parent_id( $id );
			if ( $parent_id ) {
				wc_delete_product_transients( $parent_id );
			}

			break;
		case 'product_variation':
			$data_store = WC_Data_Store::load( 'product' );
			$data_store->delete_from_lookup_table( $id, 'wc_product_meta_lookup' );
			wc_delete_product_transients( wp_get_post_parent_id( $id ) );
			$container->get( ProductAttributesLookupDataStore::class )->on_product_deleted( $id );

			break;
		case 'shop_order':
		case DataSynchronizer::PLACEHOLDER_ORDER_POST_TYPE:
			global $wpdb;

			$refunds = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id ) );

			if ( ! is_null( $refunds ) ) {
				foreach ( $refunds as $refund ) {
					wp_delete_post( $refund->ID, true );
				}
			}
			break;
	}
}