manipulations.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Category Manipulations page view
  4. *
  5. * @since 1.0.0
  6. * @package Studiou_WC_Product_Cat_Manage
  7. */
  8. // If this file is called directly, abort.
  9. if (!defined('WPINC')) {
  10. die;
  11. }
  12. // Get categories with counts for select boxes
  13. $manipulator = new Studiou_WC_Product_Cat_Manage_Manipulator(new Studiou_WC_Product_Cat_Manage_DB());
  14. $categories = $manipulator->get_categories_with_counts();
  15. ?>
  16. <div class="wrap studiou-wcpcm-wrap">
  17. <h1><?php echo esc_html__('Category Manipulations', 'studiou-wc-product-cat-manage'); ?></h1>
  18. <div class="studiou-wcpcm-notice-area">
  19. <!-- Area for displaying notices -->
  20. </div>
  21. <!-- Move Products Between Categories Operation -->
  22. <div class="studiou-wcpcm-card">
  23. <h2><?php echo esc_html__('Move products between categories', 'studiou-wc-product-cat-manage'); ?></h2>
  24. <p><?php echo esc_html__('This operation allows you to move all products from one category to another. Products will be removed from the source category and added to the target category.', 'studiou-wc-product-cat-manage'); ?></p>
  25. <form id="studiou-wcpcm-move-form" method="post">
  26. <table class="form-table">
  27. <tr>
  28. <th scope="row">
  29. <label for="source_category"><?php echo esc_html__('Source Category', 'studiou-wc-product-cat-manage'); ?></label>
  30. </th>
  31. <td>
  32. <select name="source_category" id="source_category" class="regular-text" required>
  33. <option value=""><?php echo esc_html__('-- Select Source Category --', 'studiou-wc-product-cat-manage'); ?></option>
  34. <?php foreach ($categories as $category): ?>
  35. <option value="<?php echo esc_attr($category['id']); ?>">
  36. <?php echo esc_html($category['display_name']); ?>
  37. </option>
  38. <?php endforeach; ?>
  39. </select>
  40. <p class="description"><?php echo esc_html__('Select the category from which products will be moved.', 'studiou-wc-product-cat-manage'); ?></p>
  41. </td>
  42. </tr>
  43. <tr>
  44. <th scope="row">
  45. <label for="target_category"><?php echo esc_html__('Target Category', 'studiou-wc-product-cat-manage'); ?></label>
  46. </th>
  47. <td>
  48. <select name="target_category" id="target_category" class="regular-text" required>
  49. <option value=""><?php echo esc_html__('-- Select Target Category --', 'studiou-wc-product-cat-manage'); ?></option>
  50. <?php foreach ($categories as $category): ?>
  51. <option value="<?php echo esc_attr($category['id']); ?>">
  52. <?php echo esc_html($category['display_name']); ?>
  53. </option>
  54. <?php endforeach; ?>
  55. </select>
  56. <p class="description"><?php echo esc_html__('Select the category to which products will be moved.', 'studiou-wc-product-cat-manage'); ?></p>
  57. </td>
  58. </tr>
  59. </table>
  60. <div class="submit-buttons">
  61. <button type="submit" class="button button-primary" id="studiou-wcpcm-move-button">
  62. <?php echo esc_html__('Do', 'studiou-wc-product-cat-manage'); ?>
  63. </button>
  64. <span class="spinner"></span>
  65. </div>
  66. </form>
  67. <div class="studiou-wcpcm-move-results" style="display: none;">
  68. <h3><?php echo esc_html__('Move Results', 'studiou-wc-product-cat-manage'); ?></h3>
  69. <div id="studiou-wcpcm-move-message"></div>
  70. </div>
  71. </div>
  72. <!-- Batch Description Between Categories Operation -->
  73. <div class="studiou-wcpcm-card">
  74. <h2><?php echo esc_html__('Batch description between categories', 'studiou-wc-product-cat-manage'); ?></h2>
  75. <p><?php echo esc_html__('This operation allows you to set the same description for multiple categories at once.', 'studiou-wc-product-cat-manage'); ?></p>
  76. <form id="studiou-wcpcm-batch-description-form" method="post">
  77. <table class="form-table">
  78. <tr>
  79. <th scope="row">
  80. <label for="categories_list"><?php echo esc_html__('Select Categories', 'studiou-wc-product-cat-manage'); ?></label>
  81. </th>
  82. <td>
  83. <div class="studiou-wcpcm-categories-list-container">
  84. <div class="studiou-wcpcm-list-actions">
  85. <button type="button" id="studiou-wcpcm-check-all" class="button">
  86. <?php echo esc_html__('Check All', 'studiou-wc-product-cat-manage'); ?>
  87. </button>
  88. <button type="button" id="studiou-wcpcm-uncheck-all" class="button">
  89. <?php echo esc_html__('Uncheck All', 'studiou-wc-product-cat-manage'); ?>
  90. </button>
  91. </div>
  92. <div class="studiou-wcpcm-categories-list" id="categories_list">
  93. <?php foreach ($categories as $category): ?>
  94. <label class="studiou-wcpcm-category-item">
  95. <input type="checkbox" name="selected_categories[]" value="<?php echo esc_attr($category['id']); ?>">
  96. <span><?php echo esc_html($category['display_name']); ?></span>
  97. </label>
  98. <?php endforeach; ?>
  99. </div>
  100. </div>
  101. <p class="description"><?php echo esc_html__('Select the categories for which you want to set the description.', 'studiou-wc-product-cat-manage'); ?></p>
  102. </td>
  103. </tr>
  104. <tr>
  105. <th scope="row">
  106. <label for="category_description"><?php echo esc_html__('Product categories description', 'studiou-wc-product-cat-manage'); ?></label>
  107. </th>
  108. <td>
  109. <textarea name="category_description" id="category_description" rows="5" cols="50" class="large-text"></textarea>
  110. <p class="description"><?php echo esc_html__('Enter the description that will be applied to all selected categories.', 'studiou-wc-product-cat-manage'); ?></p>
  111. </td>
  112. </tr>
  113. </table>
  114. <div class="submit-buttons">
  115. <button type="submit" class="button button-primary" id="studiou-wcpcm-batch-description-button">
  116. <?php echo esc_html__('Do', 'studiou-wc-product-cat-manage'); ?>
  117. </button>
  118. <span class="spinner"></span>
  119. </div>
  120. </form>
  121. <div class="studiou-wcpcm-batch-description-results" style="display: none;">
  122. <h3><?php echo esc_html__('Batch Description Results', 'studiou-wc-product-cat-manage'); ?></h3>
  123. <div id="studiou-wcpcm-batch-description-message"></div>
  124. </div>
  125. </div>
  126. <!-- Important Notes -->
  127. <div class="studiou-wcpcm-card">
  128. <h2><?php echo esc_html__('Important Notes', 'studiou-wc-product-cat-manage'); ?></h2>
  129. <ul>
  130. <li><?php echo esc_html__('Products can be assigned to multiple categories. This operation will remove the product from the source category and add it to the target category.', 'studiou-wc-product-cat-manage'); ?></li>
  131. <li><?php echo esc_html__('If a product is only assigned to the source category, it will be moved entirely to the target category.', 'studiou-wc-product-cat-manage'); ?></li>
  132. <li><?php echo esc_html__('If a product is assigned to multiple categories including the source category, it will remain in the other categories and be moved to the target category.', 'studiou-wc-product-cat-manage'); ?></li>
  133. <li><?php echo esc_html__('The operation processes all products regardless of their status (published, draft, private).', 'studiou-wc-product-cat-manage'); ?></li>
  134. <li><?php echo esc_html__('The batch description operation will overwrite the existing descriptions for all selected categories.', 'studiou-wc-product-cat-manage'); ?></li>
  135. </ul>
  136. </div>
  137. </div>