WC_REST_Legacy_Products_Controller::delete_post()protectedWC 1.0

Deprecated from version 3.0.0. It is no longer supported and can be removed in future releases. It is recommended to replace this function with the same one.

Delete post.

Method of the class: WC_REST_Legacy_Products_Controller{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->delete_post( $id );
$id(int|WP_Post) (required)
Post ID or WP_Post instance.

Changelog

Deprecated since 3.0.0

WC_REST_Legacy_Products_Controller::delete_post() code WC 8.7.0

protected function delete_post( $id ) {
	if ( ! empty( $id->ID ) ) {
		$id = $id->ID;
	} elseif ( ! is_numeric( $id ) || 0 >= $id ) {
		return;
	}

	// Delete product attachments.
	$attachments = get_posts( array(
		'post_parent' => $id,
		'post_status' => 'any',
		'post_type'   => 'attachment',
	) );

	foreach ( (array) $attachments as $attachment ) {
		wp_delete_attachment( $attachment->ID, true );
	}

	// Delete product.
	$product = wc_get_product( $id );
	$product->delete( true );
}