WC_Post_Data::delete_post PHP Method

delete_post() public static method

Removes variations etc belonging to a deleted post, and clears transients.
public static delete_post ( mixed $id )
$id mixed ID of post being deleted
    public static function delete_post($id)
    {
        global $woocommerce, $wpdb;
        if (!current_user_can('delete_posts')) {
            return;
        }
        if ($id > 0) {
            $post_type = get_post_type($id);
            switch ($post_type) {
                case 'product':
                    $child_product_variations = get_children('post_parent=' . $id . '&post_type=product_variation');
                    if (!empty($child_product_variations)) {
                        foreach ($child_product_variations as $child) {
                            wp_delete_post($child->ID, true);
                        }
                    }
                    $child_products = get_children('post_parent=' . $id . '&post_type=product');
                    if (!empty($child_products)) {
                        foreach ($child_products as $child) {
                            $child_post = array();
                            $child_post['ID'] = $child->ID;
                            $child_post['post_parent'] = 0;
                            wp_update_post($child_post);
                        }
                    }
                    if ($parent_id = wp_get_post_parent_id($id)) {
                        wc_delete_product_transients($parent_id);
                    }
                    break;
                case 'product_variation':
                    wc_delete_product_transients(wp_get_post_parent_id($id));
                    break;
                case 'shop_order':
                    $refunds = $wpdb->get_results($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id));
                    if (!is_null($refunds)) {
                        foreach ($refunds as $refund) {
                            wp_delete_post($refund->ID, true);
                        }
                    }
                    break;
            }
        }
    }