|
|
@@ -438,6 +438,84 @@ class Studiou_WC_Product_Cat_Manage_Manipulator {
|
|
|
return $products ? array_map('intval', $products) : array();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Update descriptions for multiple categories
|
|
|
+ *
|
|
|
+ * @param array $category_ids Array of category IDs
|
|
|
+ * @param string $description New description for categories
|
|
|
+ * @return array Result with counts and message
|
|
|
+ * @throws Exception On error
|
|
|
+ */
|
|
|
+ public function update_categories_description($category_ids, $description) {
|
|
|
+ $updated_count = 0;
|
|
|
+ $failed_count = 0;
|
|
|
+ $category_names = array();
|
|
|
+
|
|
|
+ // Debug logging
|
|
|
+ if (defined('WP_DEBUG') && WP_DEBUG) {
|
|
|
+ error_log('STUDIOU WC: Starting batch description update for ' . count($category_ids) . ' categories');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update each category
|
|
|
+ foreach ($category_ids as $category_id) {
|
|
|
+ // Get category term
|
|
|
+ $category = get_term($category_id, 'product_cat');
|
|
|
+
|
|
|
+ if (is_wp_error($category) || !$category) {
|
|
|
+ $failed_count++;
|
|
|
+ if (defined('WP_DEBUG') && WP_DEBUG) {
|
|
|
+ error_log('STUDIOU WC: Error getting category ' . $category_id . ': ' . ($category ? $category->get_error_message() : 'Category not found'));
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update category description
|
|
|
+ $result = wp_update_term($category_id, 'product_cat', array(
|
|
|
+ 'description' => $description
|
|
|
+ ));
|
|
|
+
|
|
|
+ if (!is_wp_error($result)) {
|
|
|
+ $updated_count++;
|
|
|
+ $category_names[] = $category->name;
|
|
|
+ if (defined('WP_DEBUG') && WP_DEBUG) {
|
|
|
+ error_log('STUDIOU WC: Successfully updated description for category ' . $category_id . ' (' . $category->name . ')');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $failed_count++;
|
|
|
+ if (defined('WP_DEBUG') && WP_DEBUG) {
|
|
|
+ error_log('STUDIOU WC: Error updating category ' . $category_id . ': ' . $result->get_error_message());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Generate result message
|
|
|
+ if ($updated_count === 0) {
|
|
|
+ $message = sprintf(
|
|
|
+ __('Failed to update any category descriptions. %d categories encountered errors.', 'studiou-wc-product-cat-manage'),
|
|
|
+ $failed_count
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $message = sprintf(
|
|
|
+ __('Successfully updated descriptions for %d categories: %s', 'studiou-wc-product-cat-manage'),
|
|
|
+ $updated_count,
|
|
|
+ implode(', ', array_slice($category_names, 0, 5)) . ($updated_count > 5 ? sprintf(__(', and %d more', 'studiou-wc-product-cat-manage'), $updated_count - 5) : '')
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($failed_count > 0) {
|
|
|
+ $message .= ' ' . sprintf(
|
|
|
+ __('Note: %d categories failed to update due to errors.', 'studiou-wc-product-cat-manage'),
|
|
|
+ $failed_count
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return array(
|
|
|
+ 'updated_count' => $updated_count,
|
|
|
+ 'failed_count' => $failed_count,
|
|
|
+ 'message' => $message
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Get all categories with product counts for select lists
|
|
|
*
|