WC_API_Products::clear_product()protectedWC 1.0

Clear product

Method of the class: WC_API_Products{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->clear_product( $product_id );
$product_id(int) (required)
-

WC_API_Products::clear_product() code WC 8.7.0

protected function clear_product( $product_id ) {
	if ( ! is_numeric( $product_id ) || 0 >= $product_id ) {
		return;
	}

	// Delete product attachments
	$attachments = get_children( array(
		'post_parent' => $product_id,
		'post_status' => 'any',
		'post_type'   => 'attachment',
	) );

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

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