WordPress at Your Fingertips
function is not described

WC_Post_Data::delete_post() public WC 1.0

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

{} It's a method of the class: WC_Post_Data{}

No Hooks.

Return

null. Nothing.

Usage

$result = WC_Post_Data::delete_post( $id );
$id(mixed) (required)
ID of post being deleted.

Code of WC_Post_Data::delete_post() WC 5.7.1

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':
			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;
	}
}