Plugin Directory

Changeset 2981934


Ignore:
Timestamp:
10/21/2023 07:10:40 AM (2 years ago)
Author:
themeparrot
Message:

release 1.2.1

Location:
extra-product-addons-for-woocommerce/trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • extra-product-addons-for-woocommerce/trunk/App/Controllers/Admin/FormEditor.php

    r2961872 r2981934  
    3434        );
    3535
     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
    3646        if (!ProPlugin::isActive()) {
    3747            add_meta_box(
     
    5262    public function formBuilderCallback($post) {
    5363        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        }
    54112    }
    55113
     
    82140           
    83141            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                }
    86148            }
    87149            // Sanitize data
    88             $form_builder_json = json_encode($data);
     150            $form_builder_json = json_encode($data,JSON_UNESCAPED_UNICODE);
    89151
    90152            // to escape "
     
    99161            }
    100162        }
     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        }
    101180    }
    102181}
  • extra-product-addons-for-woocommerce/trunk/App/Controllers/Assets.php

    r2690767 r2981934  
    7373            $settings = get_option(EPAFW_SETTINGS_KEY, Settings::default());
    7474            $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'),
    7677            ];
    7778           
  • extra-product-addons-for-woocommerce/trunk/App/Controllers/Frontend/Form.php

    r2961872 r2981934  
    66
    77use EPAFW\App\Controllers\Admin\Settings;
     8use EPAFW\App\Helpers\FieldsFromCategoryPosts;
    89use EPAFW\App\Helpers\ParseInput;
    910use EPAFW\App\Helpers\WPML;
     
    3031        $this->fields = [];
    3132        $this->form_ids = [];
     33
     34        $post_found_ids = [];
     35
     36        $product_category_ids = wp_get_post_terms($product_id, 'product_cat', ['fields' => 'ids']);
    3237
    3338        $form_ids = get_post_meta($product_id, EPAFW_PRODUCT_META_KEY, true);
     
    4449           
    4550            foreach ($form_ids as $id) {
     51                // var_dump(get_post_status($id));
    4652                if (get_post_status($id) == 'publish') {
    4753                    $fields_json = get_post_meta($id, EPAFW_FORM_META_KEY, true);
    4854                    $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            }
    5895        }
    5996    }
     
    168205            $this->injectWooCommerceFormFieldClasses();
    169206        }
    170 
    171207        new FormRender($this->fields, $this->form_ids);
     208        // echo "<pre>";
     209        // var_dump($this->form_ids);
     210        // echo "</pre>";
    172211    }
    173212
  • extra-product-addons-for-woocommerce/trunk/App/Controllers/PostType.php

    r2690767 r2981934  
    7676    {
    7777        $columns['author'] = 'Author';
     78        $columns['category'] = 'Product Category';
    7879        return $columns;
    7980    }
     
    9394    {
    9495        // 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        }
    95108    }
    96109}
  • extra-product-addons-for-woocommerce/trunk/Assets/JS/epafw-admin.js

    r2961872 r2981934  
    22
    33    const epafw_form_builder = {
    4         woocommerce: epafwObject.woocommerce,
    5 
     4        woocommerce: epafwObject.woocommerce, 
     5       
    66        init: function () {
    77            let fields = epafwObject.fields;
     
    1414                            epafw_form_builder.show_options_header(field);
    1515                            epafw_form_builder.hide_unwanted_fields(field, 'select');
     16                            epafw_form_builder.add_requiredTag(field);
    1617                        }
    1718                    },
     
    1920                        onadd: function (field) {
    2021                            epafw_form_builder.show_options_header(field);
     22                            epafw_form_builder.add_requiredTag(field);
    2123                        }
    2224                    },
     
    2527                            epafw_form_builder.show_options_header(field);
    2628                            epafw_form_builder.show_min_max_options(field);
     29                            epafw_form_builder.add_requiredTag(field);
    2730                        }
    2831                    },
     
    3033                        onadd: function(field){
    3134                            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);
    3246                        }
    3347                    },
     
    7488                return "Percentage (%)";
    7589            else
    76                 return "Value (optional)";
     90                return "Value(required)";
    7791        },
    7892        show_min_max_options(field){
     
    98112                    break;
    99113                case "text":
     114                    $('#'+field.id+" .format-wrap").css('display', 'none');
    100115                    if($('#'+field.id+' .subtype-wrap .input-wrap select option:selected').val() === 'range'){
    101116                        $('#'+field.id+" .maxlength-wrap").css('display', 'none');
     
    106121                        $('#'+field.id+" .step-wrap").css('display', 'block');
    107122                        $('#'+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
    109131                        $('#'+field.id+' .maxlength-wrap').css('display', 'none');
    110132                        $('#'+field.id+' .fld-slidercolor option').each(function(){
     
    117139                    }
    118140                    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;
    119148            }
     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
    120187        }
    121188    }
  • extra-product-addons-for-woocommerce/trunk/Assets/JS/epafw-frontend.js

    r2690767 r2981934  
    2121                            return $('<div class="epafw-form-field form-group"></div>').append(label, field, data);
    2222                        }
    23                     }
     23                    },
    2424                }
    2525            };
     
    2727
    2828            $("#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            });
    2976        }
    3077    }
    3178
    3279    epafw_form_render.init();
     80    epafw_form_render.event_listeners();
    3381
    3482});
  • extra-product-addons-for-woocommerce/trunk/config.php

    r2716615 r2981934  
    4949
    5050    // 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  
    44 * Plugin URI: https://www.themeparrot.com/
    55 * 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.0
     6 * Version: 1.2.1
    77 * Author: Themeparrot
    88 * Author URI: https://themeparrot.com/
     
    1212 * Requires PHP: 5.6
    1313 * WC requires at least: 3.0.0
    14  * WC tested up to: 7.8
     14 * WC tested up to: 8.2.1
    1515 * License: GNU General Public License v3.0
    1616 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2626
    2727// This plugin Version
    28 defined('EPAFW_PLUGIN_VERSION') or define('EPAFW_PLUGIN_VERSION', '1.2.0');
     28defined('EPAFW_PLUGIN_VERSION') or define('EPAFW_PLUGIN_VERSION', '1.2.1');
    2929
    3030require_once 'config.php'; // For define constants
  • extra-product-addons-for-woocommerce/trunk/readme.txt

    r2961872 r2981934  
    55Requires at least: 4.9.0
    66Requires PHP: 5.6
    7 Tested up to: 6.3
    8 Stable tag: 1.2.0
     7Tested up to: 6.3.2
     8Stable tag: 1.2.1
    99License: GPLv3 or later
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2222Let’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.
    2323
    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/)
    2525
    2626== Free Version Features ==
     
    5353== Premium Version ==
    5454
    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.
     55With 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.
    5656
    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/)**
    5858
    5959**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.
     
    102102
    103103== 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
    104111
    105112= 1.2.0 - 02/09/2023 =
Note: See TracChangeset for help on using the changeset viewer.