how can I delete specific categories for a product in Magento 2.Forex: I have a product with a,b,c categories, I have some conditions if the conditions meet my categories remains same but if those conditions fail I need to remove b, the category only not a,c categories. How can I achieve that?

  • Let me know whether you would like to remove programmatically? or manually – Nagaraju K May 19 '19 at 4:14
  • programmatically @NagarajuKasa – Prasanth May 19 '19 at 4:31

You need to build a category collection of the categories you want to delete.

Then it's just the case of something like this:

try {
    echo 'Category Removed';
  } catch (Exception $e) {
    echo 'Failed to remove category ' . $category->getId();
    echo $e->getMessage();

I cant be more specific without knowing more about the conditions which means delete.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.