PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets / 2.4.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets v2.4.0
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / modules / swatches / admin-product.php
shopengine / modules / swatches Last commit date
assets 4 years ago loop-product-support 4 years ago admin-product.php 4 years ago attribute-hooks.php 4 years ago frontend.php 4 years ago helper.php 4 years ago swatches.php 4 years ago
admin-product.php
201 lines
1 <?php
2
3 namespace ShopEngine\Modules\Swatches;
4
5 use ShopEngine\Traits\Singleton;
6
7 defined('ABSPATH') || exit;
8
9 class Admin_Product {
10
11 use Singleton;
12
13 public function init() {
14
15 add_action('woocommerce_product_option_terms', [$this, 'get_option_terms_product'], 10, 2);
16
17 add_action('wp_ajax_shopengine_add_new_attribute', [$this, 'add_attribute_by_ajax']);
18
19 add_action('admin_footer', [$this, 'shopengine_term_template']);
20 }
21
22
23 public function get_option_terms_product($taxonomy, $index) {
24
25 $types = Swatches::instance()->get_available_types();
26
27 if(!array_key_exists($taxonomy->attribute_type, $types)) {
28 return;
29 }
30
31 $taxonomy_name = wc_attribute_taxonomy_name($taxonomy->attribute_name);
32
33 global $thepostid;
34
35 $product_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : $thepostid; ?>
36
37 <select multiple="multiple" data-placeholder="<?php esc_attr_e('Select terms', 'shopengine'); ?>"
38 class="multiselect attribute_values wc-enhanced-select"
39 name="attribute_values[<?php echo esc_attr( $index ); ?>][]">
40 <?php
41
42 $all_terms = get_terms($taxonomy_name, apply_filters('woocommerce_product_attribute_terms', ['orderby' => 'name', 'hide_empty' => false]));
43
44 if($all_terms) {
45 foreach($all_terms as $term) {
46 echo '<option value="' . esc_attr($term->term_id) . '" ' . selected(has_term(absint($term->term_id), $taxonomy_name, $product_id), true, false) . '>' . esc_html(apply_filters('woocommerce_product_attribute_term_name', $term->name, $term)) . '</option>';
47 }
48 }
49 ?>
50 </select>
51 <button class="button plus select_all_attributes"><?php esc_html_e('Select all', 'shopengine'); ?></button>
52 <button class="button minus select_no_attributes"><?php esc_html_e('Select none', 'shopengine'); ?></button>
53 <button class="button fr plus shopengine_assign_new_attribute" data-type="<?php echo esc_attr( $taxonomy->attribute_type ) ?>">
54 <?php esc_html_e('Add new', 'shopengine'); ?>
55 </button>
56
57 <?php
58 }
59
60
61 public function add_attribute_by_ajax() {
62
63 $nonce = isset($_POST['nonce']) ? sanitize_key($_POST['nonce']) : '';
64 $tax = isset($_POST['taxonomy']) ? sanitize_key($_POST['taxonomy']) : '';
65 $type = isset($_POST['type']) ? sanitize_key($_POST['type']) : '';
66 $name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : '';
67 $slug = isset($_POST['slug']) ? sanitize_key($_POST['slug']) : '';
68 $swatch = isset($_POST['swatch']) ? sanitize_text_field($_POST['swatch']) : '';
69
70 if(!wp_verify_nonce($nonce, 'shopengine_nonce_add_attribute')) {
71 wp_send_json_error(esc_html__('Request denied', 'shopengine'));
72 }
73
74 if(empty($name) || empty($swatch) || empty($tax) || empty($type)) {
75 wp_send_json_error(esc_html__('Insufficient data', 'shopengine'));
76 }
77
78 if(!taxonomy_exists($tax)) {
79 wp_send_json_error(esc_html__('Taxonomy is not exists', 'shopengine'));
80 }
81
82 if(term_exists($name, $tax)) {
83 wp_send_json_error(esc_html__('Term already exists', 'shopengine'));
84 }
85
86 $term = wp_insert_term($name, $tax, ['slug' => $slug]);
87
88 if(is_wp_error($term)) {
89
90 wp_send_json_error($term->get_error_message());
91
92 } else {
93 $term = get_term_by('id', $term['term_id'], $tax);
94 update_term_meta($term->term_id, $type, $swatch);
95 }
96
97 wp_send_json_success(
98 [
99 'msg' => esc_html__('Successfully added', 'shopengine'),
100 'id' => $term->term_id,
101 'slug' => $term->slug,
102 'name' => $term->name,
103 ]
104 );
105 }
106
107
108 public function shopengine_term_template() {
109
110 global $pagenow, $post;
111
112 if($pagenow != 'post.php' || (isset($post) && get_post_type($post->ID) != 'product')) {
113 return;
114 }
115 ?>
116
117 <div id="shopengine_tpl_modal" class="shopengine_modal_container">
118 <div class="shopengine_modal">
119 <button type="button" class="button-link media-modal-close shopengine_modal__close">
120 <span class="media-modal-icon"></span></button>
121 <div class="shopengine_modal__header"><h2><?php esc_html_e('Add new term', 'shopengine') ?></h2></div>
122 <div class="shopengine_modal__content">
123 <p class="shopengine_term__name">
124 <label>
125 <?php esc_html_e('Name', 'shopengine') ?>
126 <input type="text" class="shopengine__input" name="name">
127 </label>
128 </p>
129 <p class="shopengine_term__slug">
130 <label>
131 <?php esc_html_e('Slug', 'shopengine') ?>
132 <input type="text" class="shopengine__input" name="slug">
133 </label>
134 </p>
135 <div class="shopengine_term__swatch">
136
137 </div>
138 <div class="hidden shopengine_term__tax"></div>
139
140 <input type="hidden" class="shopengine__input" name="nonce"
141 value="<?php echo wp_create_nonce('shopengine_nonce_add_attribute') ?>">
142 </div>
143 <div class="shopengine_modal__footer">
144 <button class="button button-secondary shopengine_modal__close"><?php esc_html_e('Cancel', 'shopengine') ?></button>
145 <button class="button button-primary shopengine_add_attribute_submit"><?php esc_html_e('Add New', 'shopengine') ?></button>
146 <span class="message"></span>
147 <span class="spinner"></span>
148 </div>
149 </div>
150 <div class="shopengine_modal__backdrop media-modal-backdrop"></div>
151 </div>
152
153 <script type="text/template" id="tmpl-shopengine__tpl_input__color">
154
155 <label><?php esc_html_e('Color', 'shopengine') ?></label><br>
156 <input type="text" class="shopengine__input shopengine_input__color" name="swatch">
157
158 </script>
159
160 <script type="text/template" id="tmpl-shopengine__tpl_input__image">
161
162 <label><?php esc_html_e('Image', 'shopengine') ?></label><br>
163
164 <div class="shopengine_term_img_thumbnail" style="float:left;margin-right:10px;">
165 <img src="<?php echo esc_url(Helper::get_dummy()) ?>" width="60px" height="60px"/>
166 </div>
167
168 <div style="line-height:60px;">
169 <input type="hidden" class="shopengine__input shopengine_input__image shopengine_term_img" name="swatch" value=""/>
170
171 <button type="button" class="shopengine_upload_img_button button">
172 <?php esc_html_e('Upload/Add image', 'shopengine'); ?>
173 </button>
174
175 <button type="button" class="shopengine_remove_img_btn button hidden">
176 <?php esc_html_e('Remove image', 'shopengine'); ?>
177 </button>
178 </div>
179
180 </script>
181
182 <script type="text/template" id="tmpl-shopengine__tpl_input__label">
183
184 <label>
185 <?php esc_html_e('Label', 'shopengine') ?>
186 <input type="text" class="shopengine__input shopengine_input__label" name="swatch">
187 </label>
188
189 </script>
190
191 <script type="text/template" id="tmpl-shopengine__tpl_input__tax">
192
193 <input type="hidden" class="shopengine__input" name="taxonomy" value="{{data.tax}}">
194 <input type="hidden" class="shopengine__input" name="type" value="{{data.type}}">
195
196 </script>
197 <?php
198 }
199 }
200
201