WC_Product_Data_Store_CPT::delete()
Method to delete a product from the database.
Method of the class: WC_Product_Data_Store_CPT{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Product_Data_Store_CPT = new WC_Product_Data_Store_CPT(); $WC_Product_Data_Store_CPT->delete( $product, $args );
- $product(WC_Product) (required) (passed by reference — &)
- Product object.
- $args(array)
- Array of args to pass to the delete method.
Default: array()
WC_Product_Data_Store_CPT::delete() WC Product Data Store CPT::delete code WC 9.4.2
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 ); } }