Changeset 2981934
- Timestamp:
- 10/21/2023 07:10:40 AM (2 years ago)
- Location:
- extra-product-addons-for-woocommerce/trunk
- Files:
-
- 1 added
- 9 edited
-
App/Controllers/Admin/FormEditor.php (modified) (4 diffs)
-
App/Controllers/Assets.php (modified) (1 diff)
-
App/Controllers/Frontend/Form.php (modified) (4 diffs)
-
App/Controllers/PostType.php (modified) (2 diffs)
-
App/Helpers/FieldsFromCategoryPosts.php (added)
-
Assets/JS/epafw-admin.js (modified) (9 diffs)
-
Assets/JS/epafw-frontend.js (modified) (2 diffs)
-
config.php (modified) (1 diff)
-
extra-product-addons-for-woocommerce.php (modified) (3 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
extra-product-addons-for-woocommerce/trunk/App/Controllers/Admin/FormEditor.php
r2961872 r2981934 34 34 ); 35 35 36 add_meta_box( 37 'epafw-product-category-box', 38 __("Product Category", 'extra-product-addons-for-woocommerce'), 39 array($this, 'productCategoryCallback'), 40 EPAFW_POST_TYPE, 41 'side', 42 'default', 43 null 44 ); 45 36 46 if (!ProPlugin::isActive()) { 37 47 add_meta_box( … … 52 62 public function formBuilderCallback($post) { 53 63 new FormBuilder($post); 64 } 65 66 public function productCategoryCallback($post){ 67 if (class_exists('WooCommerce')) { 68 $taxonomy = 'product_cat'; 69 $current_categories = wp_get_post_terms($post->ID, $taxonomy, array('fields' => 'ids')); 70 71 echo '<label>'.__("The categories you choose will determine which products the form is allocated to:", 'extra-product-addons-for-woocommerce').'</label>'; 72 echo '<div style="margin-top:10px;" id="product_category_checklist" class="categorychecklist form-no-clear">'; 73 74 // Get the top-level (parent) categories 75 $parent_categories = get_terms($taxonomy, array( 76 'taxonomy' => $taxonomy, 77 'parent' => 0, 78 )); 79 80 81 if (!empty($parent_categories)) { 82 foreach ($parent_categories as $parent_category) { 83 // Display parent category checkbox 84 if (property_exists($parent_category, 'term_id')) { 85 echo '<label class="selectit" style="margin-top:5px;">'; 86 echo '<input type="checkbox" name="product-category[]" value="' . esc_attr($parent_category->term_id) . '" ' . checked(in_array($parent_category->term_id, $current_categories), true, false) . '>'; 87 echo esc_html($parent_category->name); 88 echo '</label><br/>'; 89 90 // Get child categories of the parent 91 $child_categories = get_terms($taxonomy, array( 92 'taxonomy' => $taxonomy, 93 'parent' => $parent_category->term_id, 94 )); 95 96 if (!empty($child_categories)) { 97 foreach ($child_categories as $child_category) { 98 if (property_exists($child_category, 'term_id')) { 99 echo '<label class="selectit" style="margin-left: 20px;margin-top:5px;">'; 100 echo '<input type="checkbox" name="product-category[]" value="' . esc_attr($child_category->term_id) . '" ' . checked(in_array($child_category->term_id, $current_categories), true, false) . '>'; 101 echo esc_html($child_category->name); 102 echo '</label><br/>'; 103 } 104 } 105 } 106 } 107 } 108 } 109 110 echo '</div>'; 111 } 54 112 } 55 113 … … 82 140 83 141 foreach($data as $key => $val){ 84 $data[$key]['label'] = wp_kses_post($val['label']); 85 $data[$key]['value'] = wp_kses_post($val['value']); 142 if(isset($val['label'])){ 143 $data[$key]['label'] = wp_kses_post(strip_tags($val['label'])); 144 } 145 if(isset($val['value'])){ 146 $data[$key]['value'] = wp_kses_post($val['value']); 147 } 86 148 } 87 149 // Sanitize data 88 $form_builder_json = json_encode($data );150 $form_builder_json = json_encode($data,JSON_UNESCAPED_UNICODE); 89 151 90 152 // to escape " … … 99 161 } 100 162 } 163 164 $selected_categories = isset($_POST['product-category']) ? array_map('intval', $_POST['product-category']) : array(); 165 166 $current_categories = wp_get_post_terms($post_id, 'product_cat', array('fields' => 'ids')); 167 168 $categories_to_add = array_diff($selected_categories, $current_categories); 169 $categories_to_remove = array_diff($current_categories, $selected_categories); 170 171 if (!empty($categories_to_add)) { 172 wp_set_post_terms($post_id, $categories_to_add, 'product_cat', true); 173 } 174 175 if (!empty($categories_to_remove)) { 176 foreach ($categories_to_remove as $category_id) { 177 wp_remove_object_terms($post_id, $category_id, 'product_cat'); 178 } 179 } 101 180 } 102 181 } -
extra-product-addons-for-woocommerce/trunk/App/Controllers/Assets.php
r2690767 r2981934 73 73 $settings = get_option(EPAFW_SETTINGS_KEY, Settings::default()); 74 74 $config = [ 75 'form_style' => $settings['frontend_form_style'] 75 'form_style' => $settings['frontend_form_style'], 76 // 'textarea_error_text' => __('You can\'t enter more than {rows} rows', 'extra-product-addons-for-woocommerce'), 76 77 ]; 77 78 -
extra-product-addons-for-woocommerce/trunk/App/Controllers/Frontend/Form.php
r2961872 r2981934 6 6 7 7 use EPAFW\App\Controllers\Admin\Settings; 8 use EPAFW\App\Helpers\FieldsFromCategoryPosts; 8 9 use EPAFW\App\Helpers\ParseInput; 9 10 use EPAFW\App\Helpers\WPML; … … 30 31 $this->fields = []; 31 32 $this->form_ids = []; 33 34 $post_found_ids = []; 35 36 $product_category_ids = wp_get_post_terms($product_id, 'product_cat', ['fields' => 'ids']); 32 37 33 38 $form_ids = get_post_meta($product_id, EPAFW_PRODUCT_META_KEY, true); … … 44 49 45 50 foreach ($form_ids as $id) { 51 // var_dump(get_post_status($id)); 46 52 if (get_post_status($id) == 'publish') { 47 53 $fields_json = get_post_meta($id, EPAFW_FORM_META_KEY, true); 48 54 $fields = json_decode($fields_json); 49 if (!empty($fields) && is_array($fields)) { 50 foreach ($fields as $field) { 51 $this->fields[] = $field; 52 } 53 } 54 } 55 } 56 57 $this->form_ids = $form_ids; 55 $this->addFields($fields); 56 } 57 58 $this->form_ids = $form_ids; 59 //To Render the category based forms 60 $this->addCategoryFields($product_category_ids, $post_found_ids, (int)$id); 61 } 62 }else{ 63 //To Render the category based forms 64 $this->addCategoryFields($product_category_ids, $post_found_ids); 65 } 66 } 67 68 public function addFields($fields){ 69 if (!empty($fields) && is_array($fields)) { 70 foreach ($fields as $field) { 71 if (!in_array($field, $this->fields)) { 72 $this->fields[] = $field; 73 } 74 } 75 } 76 } 77 78 public function addCategoryFields($product_category_ids, &$post_found_ids, $id = null){ 79 foreach ($product_category_ids as $category_id) { 80 $result = FieldsFromCategoryPosts::getFieldsFromCategoryPosts($category_id, $post_found_ids, $id); 81 $post_id = $result['post_id']; 82 $field = $result['fields']; 83 $fields_json = json_encode($field); 84 85 if(!empty($fields_json)){ 86 $fields = json_decode($fields_json); 87 $this->addFields($fields); 88 } 89 90 if (!empty($post_id)) { 91 if(!in_array($post_id, $this->form_ids)){ 92 $this->form_ids[] = $post_id; 93 } 94 } 58 95 } 59 96 } … … 168 205 $this->injectWooCommerceFormFieldClasses(); 169 206 } 170 171 207 new FormRender($this->fields, $this->form_ids); 208 // echo "<pre>"; 209 // var_dump($this->form_ids); 210 // echo "</pre>"; 172 211 } 173 212 -
extra-product-addons-for-woocommerce/trunk/App/Controllers/PostType.php
r2690767 r2981934 76 76 { 77 77 $columns['author'] = 'Author'; 78 $columns['category'] = 'Product Category'; 78 79 return $columns; 79 80 } … … 93 94 { 94 95 // Silence is golden 96 if($column_name == 'category'){ 97 $categories = get_the_terms($post_id, 'product_cat'); 98 if ($categories) { 99 $category_names = array(); 100 foreach ($categories as $category) { 101 $category_names[] = $category->name; 102 } 103 echo implode(', ', $category_names); 104 } else { 105 echo __("No categories", 'extra-product-addons-for-woocommerce'); 106 } 107 } 95 108 } 96 109 } -
extra-product-addons-for-woocommerce/trunk/Assets/JS/epafw-admin.js
r2961872 r2981934 2 2 3 3 const epafw_form_builder = { 4 woocommerce: epafwObject.woocommerce, 5 4 woocommerce: epafwObject.woocommerce, 5 6 6 init: function () { 7 7 let fields = epafwObject.fields; … … 14 14 epafw_form_builder.show_options_header(field); 15 15 epafw_form_builder.hide_unwanted_fields(field, 'select'); 16 epafw_form_builder.add_requiredTag(field); 16 17 } 17 18 }, … … 19 20 onadd: function (field) { 20 21 epafw_form_builder.show_options_header(field); 22 epafw_form_builder.add_requiredTag(field); 21 23 } 22 24 }, … … 25 27 epafw_form_builder.show_options_header(field); 26 28 epafw_form_builder.show_min_max_options(field); 29 epafw_form_builder.add_requiredTag(field); 27 30 } 28 31 }, … … 30 33 onadd: function(field){ 31 34 epafw_form_builder.hide_unwanted_fields(field, 'text'); 35 } 36 }, 37 'date': { 38 onadd: function(field){ 39 epafw_form_builder.hide_unwanted_fields(field, 'date'); 40 } 41 }, 42 'file': { 43 onadd: function(field){ 44 epafw_form_builder.hide_unwanted_fields(field, 'file'); 45 epafw_form_builder.check_formbuilder_multiple(field); 32 46 } 33 47 }, … … 74 88 return "Percentage (%)"; 75 89 else 76 return "Value (optional)";90 return "Value(required)"; 77 91 }, 78 92 show_min_max_options(field){ … … 98 112 break; 99 113 case "text": 114 $('#'+field.id+" .format-wrap").css('display', 'none'); 100 115 if($('#'+field.id+' .subtype-wrap .input-wrap select option:selected').val() === 'range'){ 101 116 $('#'+field.id+" .maxlength-wrap").css('display', 'none'); … … 106 121 $('#'+field.id+" .step-wrap").css('display', 'block'); 107 122 $('#'+field.id+" .slidercolor-wrap").css('display', 'block'); 108 }else if(['color', 'url'].includes($('#'+field.id+' .subtype-wrap .input-wrap select option:selected').val())){ 123 }else if(['color', 'url', 'datetime-picker', 'time-picker', 'date-picker'].includes($('#'+field.id+' .subtype-wrap .input-wrap select option:selected').val())){ 124 if($('#'+field.id+' .subtype-wrap .input-wrap select option:selected').val() === 'color'){ 125 $('#'+field.id+" .value-wrap .input-wrap input").attr('placeholder', 'Default value (Ex. #000000)'); 126 $('#'+field.id+" .placeholder-wrap").css('display', 'none'); 127 }else if(($('#'+field.id+' .subtype-wrap .input-wrap select option:selected').val() === 'datetime-picker') || $('#'+field.id+' .subtype-wrap .input-wrap select option:selected').val() === 'time-picker'){ 128 $('#'+field.id+" .format-wrap").css('display', 'block'); 129 } 130 109 131 $('#'+field.id+' .maxlength-wrap').css('display', 'none'); 110 132 $('#'+field.id+' .fld-slidercolor option').each(function(){ … … 117 139 } 118 140 break; 141 case "date": 142 $('#'+field.id+" .value-wrap .input-wrap input").attr('placeholder', `Default value (Ex. ${epafw_form_builder.getCurrentDate()} )`); 143 $('#'+field.id+" .placeholder-wrap").css('display', 'none'); 144 break; 145 case "file": 146 $('#'+field.id+" .multiple-wrap").css('display', 'none'); 147 break; 119 148 } 149 }, 150 151 getCurrentDate:function(){ 152 var currentDate = new Date(); 153 154 var day = currentDate.getDate(); 155 var month = currentDate.getMonth() + 1; 156 var year = currentDate.getFullYear(); 157 158 var formattedDate = year + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day; 159 return formattedDate; 160 }, 161 162 add_requiredTag:function(field){ 163 $('#'+field.id+' .sortable-options .option-value').attr('required', 'required') 164 $(document).on("click", "#publish", function () { 165 $('#'+field.id+' .sortable-options .option-value').each(function(){ 166 if($(this).val() == ''){ 167 // console.log($(this).siblings('.option-label').val()); 168 alert($('#'+field.id+' .label-wrap .input-wrap .fld-label').text()+' options('+ $(this).siblings('.option-label').val() +') value is required!'); 169 $('#'+field.id+' .sortable-options .option-value').focus(); 170 } 171 }); 172 }); 173 }, 174 175 check_formbuilder_multiple:function(field){ 176 let formbuilder_multiple = $('#'+field.id+" .multiple-wrap .input-wrap input"); 177 let custom_multiple = $('#'+field.id+" .filemultiselection-wrap .input-wrap input"); 178 179 $(custom_multiple).on('change', function(){ 180 if($(custom_multiple).is(":checked")){ 181 $(formbuilder_multiple).attr("checked", true); 182 }else{ 183 $(formbuilder_multiple).attr("checked", false); 184 } 185 }); 186 120 187 } 121 188 } -
extra-product-addons-for-woocommerce/trunk/Assets/JS/epafw-frontend.js
r2690767 r2981934 21 21 return $('<div class="epafw-form-field form-group"></div>').append(label, field, data); 22 22 } 23 } 23 }, 24 24 } 25 25 }; … … 27 27 28 28 $("#epafw-warp").formRender($.extend({formData}, options)); 29 }, 30 31 event_listeners: function(field){ 32 $(document).ready(function(){ 33 $(document).on('keydown', '#epafw-warp input[type="number"]', function(e) { 34 var stepValue = parseFloat($(this).attr('step')); 35 var min = parseFloat($(this).attr('min')); 36 var max = ($(this).attr('max')) ? parseFloat($(this).attr('max')) : Number.POSITIVE_INFINITY; 37 38 if (stepValue && stepValue > 0) { 39 var keyCode = e.keyCode || e.which; 40 if ( 41 keyCode === 8 || // Backspace 42 keyCode === 9 || // Tab 43 keyCode === 46 || // Delete 44 keyCode === 37 || // Left arrow 45 keyCode === 39 || // Right arrow 46 (e.ctrlKey === true && (keyCode === 65 || keyCode === 67 || keyCode === 86 || keyCode === 88)) 47 ) { 48 return; 49 } 50 51 var currentValue = parseFloat($(this).val()); 52 53 if(isNaN(currentValue)){ 54 currentValue = (min) ? min : 1; 55 } 56 57 if (currentValue >= max) { 58 $(this).val(max) 59 e.preventDefault(); 60 } 61 62 if (keyCode === 38) { 63 if (currentValue + stepValue <= max) { 64 $(this).val(currentValue + stepValue); 65 } 66 e.preventDefault(); 67 } else if (keyCode === 40) { 68 if (currentValue - stepValue >= min) { 69 $(this).val(currentValue - stepValue); 70 } 71 e.preventDefault(); 72 } 73 } 74 }); 75 }); 29 76 } 30 77 } 31 78 32 79 epafw_form_render.init(); 80 epafw_form_render.event_listeners(); 33 81 34 82 }); -
extra-product-addons-for-woocommerce/trunk/config.php
r2716615 r2981934 49 49 50 50 // Pro plugin Url 51 define('EPAFW_PRO_PLUGIN_URL', 'https://themeparrot.com/ downloads/product-addons-for-woocommerce-and-custom-product-options');51 define('EPAFW_PRO_PLUGIN_URL', 'https://themeparrot.com/extra-product-options-custom-addons-for-woocommerce/'); -
extra-product-addons-for-woocommerce/trunk/extra-product-addons-for-woocommerce.php
r2961872 r2981934 4 4 * Plugin URI: https://www.themeparrot.com/ 5 5 * Description: Add custom product options and extra fields using the best WooCommerce Product Addons plugin in minutes. Add Custom Product Options with our drag and drop form builder. 6 * Version: 1.2. 06 * Version: 1.2.1 7 7 * Author: Themeparrot 8 8 * Author URI: https://themeparrot.com/ … … 12 12 * Requires PHP: 5.6 13 13 * WC requires at least: 3.0.0 14 * WC tested up to: 7.814 * WC tested up to: 8.2.1 15 15 * License: GNU General Public License v3.0 16 16 * License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 26 26 27 27 // This plugin Version 28 defined('EPAFW_PLUGIN_VERSION') or define('EPAFW_PLUGIN_VERSION', '1.2. 0');28 defined('EPAFW_PLUGIN_VERSION') or define('EPAFW_PLUGIN_VERSION', '1.2.1'); 29 29 30 30 require_once 'config.php'; // For define constants -
extra-product-addons-for-woocommerce/trunk/readme.txt
r2961872 r2981934 5 5 Requires at least: 4.9.0 6 6 Requires PHP: 5.6 7 Tested up to: 6.3 8 Stable tag: 1.2. 07 Tested up to: 6.3.2 8 Stable tag: 1.2.1 9 9 License: GPLv3 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 22 22 Let’s say, you are selling a customizable T-Shirt. You can let customers choose a logo, color, text to be printed on the shirt, a delivery date and more. All these can be done through the using this plugin. 23 23 24 [Demo](http://demo.themeparrot.net/extra-product-addons) | [Get PRO version](https://themeparrot.com/ downloads/product-addons-for-woocommerce-and-custom-product-options)24 [Demo](http://demo.themeparrot.net/extra-product-addons) | [Get PRO version](https://themeparrot.com/extra-product-options-custom-addons-for-woocommerce/) 25 25 26 26 == Free Version Features == … … 53 53 == Premium Version == 54 54 55 With the [Extra Product Options (Custom Addons) for WooCommerce PRO](https://themeparrot.com/ downloads/product-addons-for-woocommerce-and-custom-product-options) version, you can set price for the fields, more field types like file upload and more.55 With the [Extra Product Options (Custom Addons) for WooCommerce PRO](https://themeparrot.com/extra-product-options-custom-addons-for-woocommerce/) version, you can set price for the fields, more field types like file upload and more. 56 56 57 **[Get Premium Version](https://themeparrot.com/ downloads/product-addons-for-woocommerce-and-custom-product-options)**57 **[Get Premium Version](https://themeparrot.com/extra-product-options-custom-addons-for-woocommerce/)** 58 58 59 59 **Custom Price Fields:** Set a price for the product options. For example: You can charge + $5 when customers choose to Gift wrap the product. You can also set different prices for different options. … … 102 102 103 103 == Changelog == 104 105 106 = 1.2.1 - 20/10/2023 = 107 * Add - A product category selection option has been included in the form customization panel 108 * Add - Time format (12hrs, 24hrs) [PRO] 109 * Fix - Modify multiple file upload option [PRO] 110 104 111 105 112 = 1.2.0 - 02/09/2023 =
Note: See TracChangeset
for help on using the changeset viewer.