حذف تمام ویژگیهای محصولات ووکامرس با API ووکامرس + با پایتون
در این نوشته با کمک woocommerce api تمام ویژگیهای ووکامرس به همراه مقدار آنها را حذف میکنیم.
حذف تمام ویژگیهای محصولات ووکامرس با API ووکامرس
import requests
wcapi_url = "https://test.com/wp-json/wc/v3/"
wcapi_credentials = (
"ck_1111111111111111111111111111111111111111",
"cs_1111111111111111111111111111111111111111",
)
def get_all_attributes():
response = requests.get(
f"{wcapi_url}products/attributes",
auth=wcapi_credentials,
)
if response.status_code == 200:
return response.json()
else:
print(f"Error fetching attributes: {response.status_code}")
return []
def delete_attribute(attribute_id):
response = requests.delete(
f"{wcapi_url}products/attributes/{attribute_id}",
auth=wcapi_credentials,
)
if response.status_code == 200 or response.status_code == 204:
print(f"Attribute {attribute_id} deleted successfully.")
return True
else:
print(f"Error deleting attribute {attribute_id}: {response.status_code}")
return False
def delete_all_attributes():
attributes = get_all_attributes()
if attributes:
for attribute in attributes:
attribute_id = attribute["id"]
delete_attribute(attribute_id)
else:
print("No attributes found on the website.")
if __name__ == "__main__":
delete_all_attributes()
پایان.!
اگر نیاز به آموزشهای بیشتری در ارتباط با وردپرس دارید در بخش نظرات همین نوشته برای ما بنویسید.
برای امتیاز به این نوشته کلیک کنید!
[کل: 1 میانگین: 5]



















همیشه فکر میکردم باید افزونه نصب کنم ولی این خیلی سبکتره
موفق باشید.
خیلی سریع و بدون خطا اجرا شد
موفق باشید.
جالبه که حتی ویژگیهای سفارشی هم پاک شدن
خوشحالیم این کد برای شما مناسب بود. موفق باشید.
من با API زیاد کار نکرده بودم ولی کد خیلی ساده و قابل فهم بود
خوشحالیم این کد برای شما مناسب بود. موفق باشید.
تست کردم واقعا همه ویژگیها رو حذف کرد
خوشحالیم این کد برای شما مناسب بود. موفق باشید.