Magento 2 Update Product Attributes for All Products in a Certain Category

Update Product Attributes in Bulk Using Product Grid

Magento 2 gives you the ability to update product attributes in bulk. Just go to the product grid at back-end(Catalog > Products), and you can select multiple products for which you want to update the product attribute value. Then from the action drop-down menu(upper left), select “Update Attributes”. You will be brought to a product edit page, instead of updating a single product, this time you are updating for all products you have selected. Change the value of product attribute by clicking on “Change” checkbox right below the attribute you would like to update, then the attribute will become enable to accepts your updates. When you are done editing, click on save button, all products will be updated with new attribute value.

You can even apply attribute filters, e.g. availability, qty, product type, etc.

Magento 2 Update Product Attributes for All Products in a Certain Category

However Magento 2 does not allow you to search product by categories in the product grid, you are reading this post because you want to update product attributes for all products in a certain category, for example you want to disable all products in one category.

Below is a simple PHP script to do that:

  • $categoryId is the Id of the category
  • attribue_code is the attribute code(string)
  • $value is the attribute value, in the script above, I was updating a YES/NO attribute, 1 = YES, 0 = NO

Replace $categoryId, $value, attribue_code for your needs, then run the script from CLI, or directly execute it in your browser.