WC_API_Products::clear_product( int $product_id )
Clear product
Description Description
Parameters Parameters
- $product_id
-
(Required)
Source Source
File: includes/legacy/api/v2/class-wc-api-products.php
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();
}