WC_Product_Data_Store_CPT::delete( WC_Product $product, array $args = array() )
Method to delete a product from the database.
Description Description
Parameters Parameters
- $product
-
(Required) Product object.
- $args
-
(Optional) Array of args to pass to the delete method.
Default value: array()
Source Source
File: includes/data-stores/class-wc-product-data-store-cpt.php
public function delete( &$product, $args = array() ) {
$id = $product->get_id();
$post_type = $product->is_type( 'variation' ) ? 'product_variation' : 'product';
$args = wp_parse_args(
$args,
array(
'force_delete' => false,
)
);
if ( ! $id ) {
return;
}
if ( $args['force_delete'] ) {
do_action( 'woocommerce_before_delete_' . $post_type, $id );
wp_delete_post( $id );
$product->set_id( 0 );
do_action( 'woocommerce_delete_' . $post_type, $id );
} else {
wp_trash_post( $id );
$product->set_status( 'trash' );
do_action( 'woocommerce_trash_' . $post_type, $id );
}
}