Using the Python ShopifyAPI library, version 12.3.0 I want to delete a specific product option.
def remove_product_option(self, product_id):
product = self.get_product_by_id(product_id)
option_name = self.config[‘option_to_delete’]
for i, option in enumerate(product.options):
if option.name == option_name:
product.options.pop(i)
product.save()
This code is not working. There are no error messages, but the product.save() returns false. What can be the problem, and how can I fix it?
Edit:
It appears like you cannot delete a product option if it has values. The solution would be to manually delete the option using the Online Store, because as far as I could find there is no way to do this with the API.
2
Answers
It appears like you cannot delete a product option if it has values. The solution would be to manually delete the option using the Online Store, because as far as I could find there is no way to do this with the API.
Apparently there is a way to do this with the API. The issue is you can’t just delete the option if there will be resulting duplicate variants. For example:
Color, Size, Pattern
White, medium, striped
White, medium, solid
You can’t delete Pattern as it would result in 2 variants with the same values White, medium. You have to manually delete one of the variants first, before deleting the "Pattern" option. I hope that makes sense. Once there are no duplicates that would be created, you can delete the option.
Shopify’s answer in their community: https://community.shopify.com/c/products-variants-and/deleting-specific-product-option-using-shopify-api/m-p/2170216