---
title: "How to Remove/Delete Product programmatically in Magento 2"
url: "https://magecomp.com/blog/remove-delete-product-programmatically-in-magento-2/"
date: "2020-12-07T14:43:46+00:00"
modified: "2025-02-20T08:55:26+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 313
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Manage your products catalog by deleting the unwanted products. Check out the steps to Remove/Delete Product programmatically in Magento 2"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Apply Coupon Code While Programmatically Adding Product to Cart In Magento 2"
    url: "https://magecomp.com/blog/apply-coupon-code-while-programmatically-adding-product-to-cart-in-magento-2/"
  - title: "Guide for Magento 2 Product Review Import Export"
    url: "https://magecomp.com/blog/guide-for-magento-2-product-review-import-export/"
  - title: "How to Override Product Shipping Price in Magento 2"
    url: "https://magecomp.com/blog/override-product-shipping-price-magento-2/"
---

# How to Remove/Delete Product programmatically in Magento 2

_Published: December 7, 2020_  
_Author: Dhiren Vasoya_  

![How to Remove Delete Product programmatically in Magento 2](https://magecomp.com/blog/wp-content/uploads/2020/12/How-to-Remove-Delete-Product-programmatically-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Welcome to Magento “How To” Blog series. Today let’s learn about How to Remove/Delete Product programmatically in Magento 2. Previously I have shared [**How to Hide Price for Not Logged In Customers in Magento 2**](https://magecomp.com/blog/hide-price-for-not-logged-in-customers-magento-2/).
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Introduction:
Your Magento store is up and running but there is always a need to make some changes with products. Due to any reason you don’t need some products in your store and need to be removed from your products list. So here I am sharing How to Remove/Delete Product programmatically in Magento 2.
## Steps to Remove/Delete Product programmatically in Magento 2:
**Step 1:** Create one file product_remove.php in the Magento root directory then add the below code.
```
<?php
use MagentoFrameworkAppInterface;
try
{
    require_once __DIR__ . '/app/bootstrap.php';
}
catch (Exception $e)
{
    echo 'Autoload error: ' . $e->getMessage();
    exit(1);
}
try
{
    $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $appState = $objectManager->get('MagentoFrameworkAppState');
    $appState->setAreaCode('frontend');

    $productRepository = $objectManager->get('MagentoCatalogModelProductRepository');
    $registry = $objectManager->get('MagentoFrameworkRegistry');

    $registry->register('isSecureArea', true);

    //There are two ways to remove products using SKU or product id.
    // using sku to remove product
    $sky="your sku here";
    $productRepository->deleteById($sky);

    //using product id to remove product
    $product_id = 1; //here your product id
    $product = $productRepository->getById($product_id);
    $productRepository->delete($product);

    echo $sky." Your Product Remove Successfully.";
}
catch(Exception $e)
{
    print_r($e->getMessage());
}
```

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-6.webp)](https://magecomp.com/magento-malware-removal.html)

**Step 2:** After adding the above code run like
https://yourdomain/product_remove.php/
That’s it.
## Conclusion:
Accordingly, you can Remove/Delete Product programmatically in Magento 2 and keep your products catalog up-to-date. If you face difficulty while implementing the above steps, mention it in the comment section below. Help your fellow Magento friends by sharing the article with them.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/remove-delete-product-programmatically-in-magento-2/](https://magecomp.com/blog/remove-delete-product-programmatically-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-10 11:33:53 UTC_  
