Plugin Directory

Changeset 3202511


Ignore:
Timestamp:
12/04/2024 04:10:38 PM (15 months ago)
Author:
triopsi
Message:

New trunk

Location:
extra-product-data-for-woocommerce/trunk
Files:
4 added
2 deleted
23 edited
2 moved

Legend:

Unmodified
Added
Removed
  • extra-product-data-for-woocommerce/trunk/CHANGELOG.md

    r3198064 r3202511  
     1# [1.3.0](https://git.triopsi.dev/triopsi/extra-product-data-for-woocommerce/compare/v1.2.0...v1.3.0) (2024-11-30)
     2
     3
     4### Features
     5
     6* add more field types checkboxes, radio and selects ([385f3de](https://git.triopsi.dev/triopsi/extra-product-data-for-woocommerce/commit/385f3de1db8d22c143fbaf731e8a57660886d4bb))
     7* edit option for admins in order overview ([24f0d3f](https://git.triopsi.dev/triopsi/extra-product-data-for-woocommerce/commit/24f0d3f6daed2450f5f98391aa3c0cdfa62bf4f1))
     8
     9# [1.2.0](https://git.triopsi.dev/triopsi/extra-product-data-for-woocommerce/compare/v1.1.2...v1.2.0) (2024-11-27)
     10
     11
     12### Features
     13
     14* Add Edit Button in the order overview. ([d5136ed](https://git.triopsi.dev/triopsi/extra-product-data-for-woocommerce/commit/d5136ed9bf985d90a22b2e917d1e8a0d4a3d7615))
     15
    116## [1.1.2](https://git.triopsi.dev/triopsi/extra-product-data-for-woocommerce/compare/v1.1.1...v1.1.2) (2024-11-20)
    217
  • extra-product-data-for-woocommerce/trunk/assets/css/admin-backend.css

    r3198064 r3202511  
     1/*
     2* Admin Backend Styles
     3* Plugin: Extra Product Data for WooCommerce
     4* Author: Triopsi
     5*/
    16#extra-product-data {
    27  padding: 10px 10px;
     
    1015}
    1116
     17/*
     18Out Table Styles
     19*/
     20table.exprdawc_field_table {
     21  width: 100%;
     22  border-collapse: collapse;
     23}
    1224table.exprdawc_field_table tr:nth-child(even) {
    13   background-color: #dedede;
    14 }
    15 table.exprdawc_field_table tr {
    16   border-bottom: 1px solid #a6a6a6;
    17 }
    18 table.exprdawc_field_table tr:last-child {
     25  background-color: #f9f9f9;
     26}
     27table.exprdawc_field_table tr.exprdawc_fields_wrapper {
     28  border-bottom: 1px solid #ddd;
     29}
     30table.exprdawc_field_table tr.exprdawc_fields_wrapper:hover {
     31  background-color: #f1f1f1;
     32}
     33table.exprdawc_field_table tr.exprdawc_fields_wrapper:last-child {
    1934  border-bottom: none;
    2035}
    21 table.exprdawc_field_table tbody tr:hover {
     36table.exprdawc_field_table td {
     37  padding: 0px;
     38}
     39table.exprdawc_field_table tfoot tr {
     40  background-color: #f5f5f5;
     41  border: 1px solid #ccc;
     42}
     43table.exprdawc_field_table tfoot td {
     44  padding: 10px;
     45  text-align: center;
     46  vertical-align: middle;
     47}
     48table.exprdawc_field_table tfoot .button {
     49  padding: 5px;
     50  line-height: 13px;
     51}
     52
     53/*
     54In Table Styles
     55*/
     56table.exprdawc_fields_table {
     57  width: 100%;
     58  border-collapse: collapse;
     59}
     60table.exprdawc_fields_table tr {
     61  border: 0px;
     62}
     63table.exprdawc_fields_table tbody td {
     64  vertical-align: middle;
     65  padding: 10px;
     66}
     67table.exprdawc_fields_table tbody td input[type=text],
     68table.exprdawc_fields_table tbody td input[type=number],
     69table.exprdawc_fields_table tbody td textarea {
     70  width: 100%;
     71  padding: 5px;
     72  border: 1px solid #ccc;
     73  border-radius: 4px;
     74  box-sizing: border-box;
     75}
     76table.exprdawc_fields_table tbody td select {
     77  width: 100%;
     78  padding: 5px;
     79  border: 1px solid #ccc;
     80  border-radius: 4px;
     81  box-sizing: border-box;
     82  text-overflow: ellipsis;
     83}
     84table.exprdawc_fields_table tbody td button.add_rule,
     85table.exprdawc_fields_table tbody td button.exprdawc_remove_custom_field,
     86table.exprdawc_fields_table tbody td button.remove_rule {
     87  padding: 5px;
     88  line-height: 13px;
     89}
     90table.exprdawc_fields_table tbody td.move i {
     91  cursor: move;
     92}
     93table.exprdawc_fields_table tbody td.cl-arr i {
     94  cursor: pointer;
     95}
     96
     97table.exprdawc_settings_table {
     98  width: 100%;
     99}
     100table.exprdawc_settings_table label.exprdawc_label {
     101  float: none;
     102  padding: 0px;
     103  margin: 5px 0px;
     104  text-align: left;
     105  display: flex;
     106  width: auto;
     107  align-items: center;
     108}
     109table.exprdawc_settings_table label.exprdawc_label .checkbox {
     110  margin-right: 5px !important;
     111}
     112table.exprdawc_settings_table td {
     113  vertical-align: middle;
     114  padding: 10px;
     115}
     116
     117table.exprdawc_options_table {
     118  width: 100%;
     119  border-collapse: collapse;
     120  margin-top: 10px;
     121  border: 1px solid #ccc;
     122}
     123table.exprdawc_options_table th,
     124table.exprdawc_options_table td {
     125  padding: 10px;
     126  text-align: left;
     127  border-bottom: 1px solid #ddd;
     128}
     129table.exprdawc_options_table th {
    22130  background-color: #f1f1f1;
    23131}
    24 table.exprdawc_field_table tbody td {
    25   text-align: center;
    26   vertical-align: middle;
    27 }
    28 table.exprdawc_field_table tbody td input[type=text] {
    29   width: 100%;
    30 }
    31 table.exprdawc_field_table tbody td.move i {
    32   cursor: move;
     132table.exprdawc_options_table tr:hover {
     133  background-color: #f9f9f9;
     134}
     135table.exprdawc_options_table .button {
     136  padding: 5px 10px;
     137  border: none;
     138  border-radius: 4px;
     139  background-color: #0073aa;
     140  color: #fff;
     141  cursor: pointer;
     142}
     143table.exprdawc_options_table .button:hover {
     144  background-color: #005a87;
     145  color: #fff;
    33146}
    34147
     
    67180}
    68181
     182.exprdawc_panel {
     183  display: block;
     184}
     185.exprdawc_panel h2 {
     186  font-size: 1.2em !important;
     187  padding: 0px 0px 10px 0px !important;
     188}
    69189.exprdawc_panel .wc-metabox {
    70190  background: #fff;
     
    80200.exprdawc_panel .wc-metabox.exprdawc_attribute h3 .sort {
    81201  margin-top: 0.25em;
    82 }
    83 
    84 .exprdawc_panel {
    85   display: block;
    86202}
    87203
     
    92208  content: "\f163";
    93209}
     210
     211.exprdawc_conditional_logic_table {
     212  width: 100%;
     213  border-collapse: collapse;
     214  margin-bottom: 20px;
     215}
     216.exprdawc_conditional_logic_table th,
     217.exprdawc_conditional_logic_table td {
     218  padding: 10px;
     219  border: 1px solid #ddd;
     220  text-align: left;
     221}
     222.exprdawc_conditional_logic_table th {
     223  background-color: #f9f9f9;
     224  font-weight: bold;
     225}
     226.exprdawc_conditional_logic_table .exprdawc_label {
     227  display: block;
     228  margin-bottom: 5px;
     229  font-weight: bold;
     230}
     231.exprdawc_conditional_logic_table .exprdawc_input {
     232  width: 100%;
     233  padding: 5px;
     234  border: 1px solid #ccc;
     235  border-radius: 4px;
     236  box-sizing: border-box;
     237}
     238.exprdawc_conditional_logic_table .exprdawc_checkbox {
     239  width: auto;
     240}
     241.exprdawc_conditional_logic_table .exprdawc_textarea {
     242  width: 100%;
     243  padding: 8px;
     244  border: 1px solid #ccc;
     245  border-radius: 4px;
     246}
     247.exprdawc_conditional_logic_table .exprdawc_no_entry_message {
     248  color: #a00;
     249  font-weight: bold;
     250}
     251.exprdawc_conditional_logic_table h2 {
     252  text-align: left;
     253  text-transform: uppercase;
     254}
     255.exprdawc_conditional_logic_table .exprdawc_rule_group {
     256  margin-bottom: 10px;
     257  padding: 10px;
     258  border: 1px solid #ddd;
     259  background-color: #f9f9f9;
     260  border-radius: 4px;
     261}
     262.exprdawc_conditional_logic_table .exprdawc_rule_group .exprdawc_rule {
     263  display: flex;
     264  align-items: center;
     265  margin-bottom: 10px;
     266}
     267.exprdawc_conditional_logic_table .exprdawc_rule_group .exprdawc_rule .exprdawc_input {
     268  margin-right: 10px;
     269}
     270.exprdawc_conditional_logic_table .exprdawc_rule_group .exprdawc_rule .button {
     271  margin-left: 10px;
     272}
     273.exprdawc_conditional_logic_table .exprdawc_rule_group .add_rule_group {
     274  margin-top: 10px;
     275}
     276
     277.exprdawc_no_entry_message {
     278  padding-top: 75px;
     279  margin: 10px 0 0;
     280  position: relative;
     281  text-align: center;
     282  display: block;
     283  padding-bottom: 1em;
     284}
     285.exprdawc_no_entry_message::before {
     286  font-family: "Dashicons";
     287  content: "\f163";
     288  font-size: 70px;
     289  color: #eee;
     290  position: absolute;
     291  top: 0px;
     292  left: 50%;
     293  transform: translateX(-50%);
     294}
     295
     296p.exprdawc_toolbar {
     297  background-color: #f5f5f5;
     298  border: 1px solid #ccc;
     299  text-align: center;
     300  display: flex;
     301  align-items: center;
     302  justify-content: center;
     303}
     304
     305a.exprdawc-export,
     306a.exprdawc-import {
     307  -webkit-text-decoration: underline dotted;
     308          text-decoration: underline dotted;
     309  font-size: small;
     310  color: #0073aa;
     311  margin: 0 5px;
     312}
     313a.exprdawc-export::before,
     314a.exprdawc-import::before {
     315  font-family: "Dashicons";
     316  margin-right: 5px;
     317  position: relative;
     318}
     319a.exprdawc-export:hover,
     320a.exprdawc-import:hover {
     321  color: #005a87;
     322  -webkit-text-decoration: underline dotted;
     323          text-decoration: underline dotted;
     324}
     325
     326a.exprdawc-export::before {
     327  content: "\f346";
     328}
     329
     330a.exprdawc-import::before {
     331  content: "\f342";
     332}
  • extra-product-data-for-woocommerce/trunk/assets/js/wc-meta-boxes-order.js

    r3198064 r3202511  
    1111/* global wc_exprdawc_admin_order_params, woocommerce_admin_meta_boxes, wcBackboneModal */
    1212jQuery(function ($) {
     13  /**
     14   * Extra Product Data for WooCommerce Admin Order
     15   * @class ExtraProductDataAdminOrder
     16   * @description Handles the functionality for the extra product data in the WooCommerce admin order page
     17   * @since 1.0.0
     18   * @version 1.0.0
     19   * @package ExtraProductDataForWooCommerce/JS
     20   * @license GPL-2.0+
     21   * @link https://www.triopsi.dev
     22   */
    1323  var ExtraProductDataAdminOrder = /*#__PURE__*/function () {
    1424    function ExtraProductDataAdminOrder() {
     
    139149              _this2.modalView.closeButton(event);
    140150            } else {
    141               window.alert(response.error ? response.error : wc_exprdawc_admin_order_params.i18n_validation_error);
     151              window.alert(response.data.message);
    142152              _this2.unblockUI(_this2.modalView.$el.find('.wc-backbone-modal-content'));
    143153            }
     
    172182      }
    173183    }]);
    174   }();
     184  }(); // Initialize the class
    175185  new ExtraProductDataAdminOrder();
    176186});
  • extra-product-data-for-woocommerce/trunk/assets/js/wc-meta-boxes-product.js

    r3198064 r3202511  
    88/***/ (() => {
    99
     10function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
     11function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
     12function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
     13function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
     14function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
     15function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
     16function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
    1017/**
    1118 * Add custom fields to the product data meta box.
    1219 */
    1320jQuery(function ($) {
    14   // Add custom field.
    15   $('#exprdawc_add_custom_field').on('click', function () {
    16     console.log('Add custom field');
    17     var fieldIndex = $('#exprdawc_field_body .exprdawc_attribute').length;
    18     $('#exprdawc_field_body').append("\n            <tr class=\"exprdawc_attribute\">\n                <td class=\"move\"><i class=\"dashicons dashicons-move\"></i></td>\n                <td class=\"exprdawc_attribute_input_name\">                                    \n                    <input type=\"text\" name=\"extra_product_fields[".concat(fieldIndex, "][label]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.label_placeholder, "\" />\n                </td>\n                <td>\n                    <select id=\"exprdawc_attribute_type_").concat(fieldIndex, "\" name=\"extra_product_fields[").concat(fieldIndex, "][type]\" class=\"exprdawc_attribute_type\">\n                        <option value=\"text\" selected=\"selected\">").concat(exprdawc_admin_meta_boxes.short_text, "</option>\n                        <option value=\"long_text\">").concat(exprdawc_admin_meta_boxes.long_text, "</option>\n                        <option value=\"email\">").concat(exprdawc_admin_meta_boxes.email, "</option>\n                        <option value=\"number\">").concat(exprdawc_admin_meta_boxes.number, "</option>\n                        <option value=\"date\">").concat(exprdawc_admin_meta_boxes.date, "</option>\n                        <option value=\"yes-no\">").concat(exprdawc_admin_meta_boxes.yes_no, "</option>\n                    </select>\n                </td>\n                <td class=\"exprdawc_attribute_require_checkbox\">\n                    <input type=\"checkbox\" class=\"checkbox\" name=\"extra_product_fields[").concat(fieldIndex, "][required]\" value=\"1\" />\n                </td>\n                <td class=\"exprdawc_attribute_placeholder_text\">\n                    <input type=\"text\" name=\"extra_product_fields[").concat(fieldIndex, "][placeholder_text]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.placeholder_text, "\" />\n                </td>\n                <td class=\"exprdawc_attribute_help_text\">\n                    <input type=\"text\" name=\"extra_product_fields[").concat(fieldIndex, "][help_text]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.help_text, "\" />\n                </td>\n                <td>\n                    <button type=\"button\" class=\"exprdawc_remove_custom_field button\">").concat(exprdawc_admin_meta_boxes.remove, "</button>\n                </td>\n            </tr>\n            "));
    19   });
    20 
    21   // Confirm deletion of custom fields.
    22   $(document).on('click', '.exprdawc_remove_custom_field', function () {
    23     if (confirm("Are you sure you want to delete this field?")) {
    24       $(this).closest('tr').remove();
     21  /**
     22   * Class to handle the product meta box.
     23   * @class ExprdawcMetaBoxesProduct
     24   * @description Handles the functionality for the extra product data in the WooCommerce product data meta box
     25   * @since 1.0.0
     26   * @version 1.0.0
     27   * @package ExtraProductDataForWooCommerce/JS
     28   * @license GPL-2.0+
     29   * @link https://www.triopsi.dev
     30  */
     31  var ExprdawcMetaBoxesProduct = /*#__PURE__*/function () {
     32    function ExprdawcMetaBoxesProduct() {
     33      _classCallCheck(this, ExprdawcMetaBoxesProduct);
     34      this.fieldIndex = $('#exprdawc_field_body tr.exprdawc_attribute').length;
     35      this.isDirty = false;
     36      this.init();
    2537    }
    26     return false;
    27   });
    28   $('#exprdawc_attribute_container').on('click', '.exprdawc_attribute .exprdawc_remove_custom_field', function () {
    29     var parent_el = $(this).parent().parent();
    30     parent_el.remove();
    31     return false;
    32   });
    33 
    34   // Attribute ordering.
    35   $('.exprdawc_attributes tbody').sortable({
    36     items: 'tr.exprdawc_attribute',
    37     cursor: 'move',
    38     axis: 'y',
    39     handle: '.move',
    40     scrollSensitivity: 40,
    41     forcePlaceholderSize: true,
    42     helper: 'clone',
    43     opacity: 0.65,
    44     placeholder: 'wc-metabox-sortable-placeholder',
    45     start: function start(event, ui) {
    46       ui.item.css('background-color', '#f6f6f6');
    47     },
    48     stop: function stop(event, ui) {
    49       ui.item.removeAttr('style');
    50     }
    51   });
    52 
    53   // Get the name of the input and set the header.
    54   $('#exprdawc_attribute_container').on('input', '.exprdawc_attribute .exprdawc_attribute_input_name input', function () {
    55     var text = $(this).val(),
    56       target = $(this).closest('.exprdawc_attribute').find('.attribute_name');
    57     if (text) {
    58       target.text(text);
    59     }
    60   });
    61 
    62   // Get the name of the input and set the header.
    63   $('#exprdawc_attribute_container').on('input', '.exprdawc_attribute .exprdawc_attribute_input_name input', function () {
    64     var text = $(this).val(),
    65       target = $(this).closest('.exprdawc_attribute').find('.attribute_name');
    66     if (text) {
    67       target.text(text);
    68     }
    69   });
     38
     39    /**
     40     * Initialize the class.
     41     */
     42    return _createClass(ExprdawcMetaBoxesProduct, [{
     43      key: "init",
     44      value: function init() {
     45        this.bindEvents();
     46        this.noEntryContent();
     47      }
     48
     49      /**
     50       * Bind events.
     51       */
     52    }, {
     53      key: "bindEvents",
     54      value: function bindEvents() {
     55        $('#exprdawc_add_custom_field').on('click', this.addCustomField.bind(this));
     56        $(document).on('click', '.exprdawc_remove_custom_field', this.removeCustomField.bind(this));
     57        $(document).on('change', '.exprdawc_attribute_type', this.toggleOptions.bind(this));
     58        $(document).on('click', '.toggle-options', this.toggleOptionsTable.bind(this));
     59        $(document).on('click', '.add_option', this.addOption.bind(this));
     60        $(document).on('click', '.remove_option', this.removeOption.bind(this));
     61        $(document).on('click', 'a.exprdawc-export', this.exportContent.bind(this));
     62        $(document).on('click', 'a.exprdawc-import', this.importContent.bind(this));
     63        $(document).on('change', '.exprdawc_input', this.setDirty.bind(this));
     64        $(document).on('change', '.exprdawc_autocomplete_field', this.checkAutocompleteField.bind(this));
     65        $(document).on('click', '.add_rule_group', this.addRuleGroup.bind(this));
     66        $(document).on('click', '.add_rule', this.addRule.bind(this));
     67        $(document).on('click', '.remove_rule', this.removeRule.bind(this));
     68        $(document).on('change', '.exprdawc_conditional_operator', this.toggleConditionalValueField.bind(this));
     69        $(document).on('change', '.exprdawc_conditional_logic_field', this.toggleConditionalTable.bind(this));
     70        this.toggleConditionalValueFieldAll();
     71
     72        // Attribute ordering.
     73        $('.exprdawc_field_table tbody').sortable({
     74          items: 'tr.exprdawc_fields_wrapper',
     75          cursor: 'move',
     76          axis: 'y',
     77          handle: '.move',
     78          scrollSensitivity: 40,
     79          forcePlaceholderSize: true,
     80          helper: 'clone',
     81          opacity: 0.65,
     82          placeholder: 'wc-metabox-sortable-placeholder',
     83          start: function start(event, ui) {
     84            ui.item.css('background-color', '#f6f6f6');
     85          },
     86          stop: function stop(event, ui) {
     87            ui.item.removeAttr('style');
     88          }
     89        });
     90
     91        // Option ordering.
     92        $(document).on('mouseenter', '.exprdawc_options_table tbody', function () {
     93          $(this).sortable({
     94            items: 'tr',
     95            cursor: 'move',
     96            axis: 'y',
     97            handle: '.move',
     98            scrollSensitivity: 40,
     99            forcePlaceholderSize: true,
     100            helper: 'clone',
     101            opacity: 0.65,
     102            placeholder: 'wc-metabox-sortable-placeholder',
     103            start: function start(event, ui) {
     104              ui.item.css('background-color', '#f6f6f6');
     105            },
     106            stop: function stop(event, ui) {
     107              ui.item.removeAttr('style');
     108            }
     109          });
     110        });
     111
     112        // Get the name of the input and set the header.
     113        $('#exprdawc_attribute_container').on('input', '.exprdawc_attribute .exprdawc_attribute_input_name input', function () {
     114          var text = $(this).val(),
     115            target = $(this).closest('.exprdawc_attribute').find('.attribute_name');
     116          if (text) {
     117            target.text(text);
     118          }
     119        });
     120      }
     121
     122      /**
     123       * Add a custom field.
     124       */
     125    }, {
     126      key: "addCustomField",
     127      value: function addCustomField() {
     128        this.fieldIndex++;
     129        this.setDirty();
     130        $('#exprdawc_field_body').append("\n                <tr class=\"exprdawc_fields_wrapper\">\n                <td colspan=\"5\">\n                <table class=\"exprdawc_fields_table\" data-index=\"".concat(this.fieldIndex, "\">\n\t                <tbody>\n                        <tr class=\"exprdawc_attribute\">\n                            <td class=\"move\"><i class=\"dashicons dashicons-move\"></i></td>\n                            <td class=\"cl-arr\"><i class=\"dashicons dashicons-arrow-up toggle-options\"></i></td>\n                            <td class=\"exprdawc_attribute_input_name\">\n                                <input type=\"text\" name=\"extra_product_fields[").concat(this.fieldIndex, "][label]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.label_placeholder, "\" />\n                            </td>\n                            <td>\n                                <select id=\"exprdawc_attribute_type_").concat(this.fieldIndex, "\" name=\"extra_product_fields[").concat(this.fieldIndex, "][type]\" class=\"exprdawc_attribute_type\">\n                                    <option value=\"text\">").concat(exprdawc_admin_meta_boxes.short_text, "</option>\n                                    <option value=\"long_text\">").concat(exprdawc_admin_meta_boxes.long_text, "</option>\n                                    <option value=\"email\">").concat(exprdawc_admin_meta_boxes.email, "</option>\n                                    <option value=\"number\">").concat(exprdawc_admin_meta_boxes.number, "</option>\n                                    <option value=\"date\">").concat(exprdawc_admin_meta_boxes.date, "</option>\n                                    <option value=\"yes-no\">").concat(exprdawc_admin_meta_boxes.yes_no, "</option>\n                                    <option value=\"radio\">").concat(exprdawc_admin_meta_boxes.radio, "</option>\n                                    <option value=\"checkbox\">").concat(exprdawc_admin_meta_boxes.checkbox, "</option>\n                                    <option value=\"select\">").concat(exprdawc_admin_meta_boxes.select, "</option>\n                                </select>\n                            </td>\n                            <td>\n                                <button type=\"button\" class=\"exprdawc_remove_custom_field button\"><i class=\"dashicons dashicons-trash\"></i></button>\n                                <input type=\"hidden\" class=\"exprdawc_attribute_index\" name=\"extra_product_fields[").concat(this.fieldIndex, "][index]\" value=\"").concat(this.fieldIndex, "\"/>\n                            </td>\n                        </tr>\n                        <tr class=\"exprdawc_options\" style=\"display: none;\">\n                            <td colspan=\"5\">\n\n                                <table class=\"exprdawc_settings_table exprdawc_general_table\">\n                                    <tbody>\n\n                                        <!-- Text Area Option/Settings -->\n                                        <tr>\n                                            <td class=\"exprdawc_attribute_require_checkbox\">\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_required_").concat(this.fieldIndex, "\">\n                                                    <input type=\"checkbox\" id=\"exprdawc_text_required_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_checkbox checkbox\" name=\"extra_product_fields[").concat(this.fieldIndex, "][required]\" value=\"1\" />\n                                                    ").concat(exprdawc_admin_meta_boxes.require_input, "\n                                                </label>                                       \n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_autofocus_").concat(this.fieldIndex, "\">\n                                                    <input type=\"checkbox\" id=\"exprdawc_text_autofocus_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_checkbox checkbox\" name=\"extra_product_fields[").concat(this.fieldIndex, "][autofocus]\" value=\"1\" />\n                                                    ").concat(exprdawc_admin_meta_boxes.enable_autofocus, "\n                                                </label>\n\n                                                <!-- Enable Conditional Logic and show table -->\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_conditional_logic_").concat(this.fieldIndex, "\">\n                                                    <input type=\"checkbox\" id=\"exprdawc_text_conditional_logic_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_checkbox exprdawc_conditional_logic_field checkbox\" name=\"extra_product_fields[").concat(this.fieldIndex, "][conditional_logic]\" value=\"1\" />\n                                                    ").concat(exprdawc_admin_meta_boxes.enable_conditional_logic, "\n                                                </label>\n                                            </td>\n                                            <td class=\"exprdawc_attribute_placeholder_text\">\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_placeholder_text_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.placeholder_text, "</label>\n                                                <input type=\"text\" id=\"exprdawc_text_placeholder_text_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_textinput exprdawc_placeholder\" name=\"extra_product_fields[").concat(this.fieldIndex, "][placeholder_text]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.placeholder_text, "\" />\n                                            </td>\n                                            <td class=\"exprdawc_attribute_help_text\">\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_help_text_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.help_text, "</label>\n                                                <input type=\"text\" id=\"exprdawc_text_help_text_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_textinput exprdawc_helptext\" name=\"extra_product_fields[").concat(this.fieldIndex, "][help_text]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.help_text, "\" />\n                                            </td>\n                                            <td>\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_autocomplete_function_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.autocomplete_function, "</label>\n                                                <select id=\"exprdawc_autocomplete_function_").concat(this.fieldIndex, "\" name=\"extra_product_fields[").concat(this.fieldIndex, "][autocomplete]\" class=\"exprdawc_input exprdawc_attribute_type\">\n                                                    <option value=\"on\">").concat(exprdawc_admin_meta_boxes.autocomplete_on, "</option>\n                                                    <option value=\"off\">").concat(exprdawc_admin_meta_boxes.autocomplete_off, "</option>\n                                                    <option value=\"address-level1\">").concat(exprdawc_admin_meta_boxes.address_level1, "</option>\n                                                    <option value=\"address-level2\">").concat(exprdawc_admin_meta_boxes.address_level2, "</option>\n                                                    <option value=\"address-level3\">").concat(exprdawc_admin_meta_boxes.address_level3, "</option>\n                                                    <option value=\"address-level4\">").concat(exprdawc_admin_meta_boxes.address_level4, "</option>\n                                                    <option value=\"address-line1\">").concat(exprdawc_admin_meta_boxes.address_line1, "</option>\n                                                    <option value=\"address-line2\">").concat(exprdawc_admin_meta_boxes.address_line2, "</option>\n                                                    <option value=\"address-line3\">").concat(exprdawc_admin_meta_boxes.address_line3, "</option>\n                                                    <option value=\"bday\">").concat(exprdawc_admin_meta_boxes.bday, "</option>\n                                                    <option value=\"bday-day\">").concat(exprdawc_admin_meta_boxes.bday_day, "</option>\n                                                    <option value=\"bday-month\">").concat(exprdawc_admin_meta_boxes.bday_month, "</option>\n                                                    <option value=\"bday-year\">").concat(exprdawc_admin_meta_boxes.bday_year, "</option>\n                                                    <option value=\"cc-additional-name\">").concat(exprdawc_admin_meta_boxes.cc_additional_name, "</option>\n                                                    <option value=\"cc-csc\">").concat(exprdawc_admin_meta_boxes.cc_csc, "</option>\n                                                    <option value=\"cc-exp\">").concat(exprdawc_admin_meta_boxes.cc_exp, "</option>\n                                                    <option value=\"cc-exp-month\">").concat(exprdawc_admin_meta_boxes.cc_exp_month, "</option>\n                                                    <option value=\"cc-exp-year\">").concat(exprdawc_admin_meta_boxes.cc_exp_year, "</option>\n                                                    <option value=\"cc-family-name\">").concat(exprdawc_admin_meta_boxes.cc_family_name, "</option>\n                                                    <option value=\"cc-given-name\">").concat(exprdawc_admin_meta_boxes.cc_given_name, "</option>\n                                                    <option value=\"cc-name\">").concat(exprdawc_admin_meta_boxes.cc_name, "</option>\n                                                    <option value=\"cc-number\">").concat(exprdawc_admin_meta_boxes.cc_number, "</option>\n                                                    <option value=\"cc-type\">").concat(exprdawc_admin_meta_boxes.cc_type, "</option>\n                                                    <option value=\"country\">").concat(exprdawc_admin_meta_boxes.country, "</option>\n                                                    <option value=\"country-name\">").concat(exprdawc_admin_meta_boxes.country_name, "</option>\n                                                    <option value=\"email\">").concat(exprdawc_admin_meta_boxes.email, "</option>\n                                                    <option value=\"language\">").concat(exprdawc_admin_meta_boxes.language, "</option>\n                                                    <option value=\"photo\">").concat(exprdawc_admin_meta_boxes.photo, "</option>\n                                                    <option value=\"postal-code\">").concat(exprdawc_admin_meta_boxes.postal_code, "</option>\n                                                    <option value=\"sex\">").concat(exprdawc_admin_meta_boxes.sex, "</option>\n                                                    <option value=\"street-address\">").concat(exprdawc_admin_meta_boxes.street_address, "</option>\n                                                    <option value=\"tel\">").concat(exprdawc_admin_meta_boxes.tel, "</option>\n                                                    <option value=\"tel-area-code\">").concat(exprdawc_admin_meta_boxes.tel_area_code, "</option>\n                                                    <option value=\"tel-country-code\">").concat(exprdawc_admin_meta_boxes.tel_country_code, "</option>\n                                                    <option value=\"tel-extension\">").concat(exprdawc_admin_meta_boxes.tel_extension, "</option>\n                                                    <option value=\"tel-local\">").concat(exprdawc_admin_meta_boxes.tel_local, "</option>\n                                                    <option value=\"tel-local-prefix\">").concat(exprdawc_admin_meta_boxes.tel_local_prefix, "</option>\n                                                    <option value=\"tel-local-suffix\">").concat(exprdawc_admin_meta_boxes.tel_local_suffix, "</option>\n                                                    <option value=\"tel-national\">").concat(exprdawc_admin_meta_boxes.tel_national, "</option>\n                                                    <option value=\"transaction-amount\">").concat(exprdawc_admin_meta_boxes.transaction_amount, "</option>\n                                                    <option value=\"transaction-currency\">").concat(exprdawc_admin_meta_boxes.transaction_currency, "</option>\n                                                    <option value=\"url\">").concat(exprdawc_admin_meta_boxes.url, "</option>\n                                                </select>\n                                            </td>\n                                        </tr>\n                                    </tbody>\n                                </table>\n                                <hr>\n\n                                <!-- Conditional Logic -->\n\t\t\t\t                <table class=\"exprdawc_settings_table exprdawc_conditional_logic_table\" style=\"display:none;\">\n                                    <tbody>\n                                        <tr>\n                                           <td colspan=\"3\">\n                                                <label class=\"exprdawc_label\">").concat(exprdawc_admin_meta_boxes.conditionals, "</label>\n\t\t\t\t\t\t\t\t                <p>").concat(exprdawc_admin_meta_boxes.conditionals_description, "</p>\n                                                <div class=\"exprdawc_conditional_rules\">\n                                                    <div class=\"exprdawc_rule_group_container\">\n                                                        <div class=\"exprdawc_rule_group\">\n                                                            <div class=\"exprdawc_rule\">\n                                                                <select name=\"extra_product_fields[").concat(this.fieldIndex, "][conditional_rules][0][0][field]\" class=\"exprdawc_input exprdawc_conditional_field\">\n                                                                <option value=\"\">").concat(exprdawc_admin_meta_boxes.selectFieldNone, "</option>\n                                                                ").concat(this.getAllFieldsOptions(), "\n                                                                </select>\n                                                                <select name=\"extra_product_fields[").concat(this.fieldIndex, "][conditional_rules][0][0][operator]\" class=\"exprdawc_input exprdawc_conditional_operator\">\n                                                                    <option value=\"field_is_empty\">").concat(exprdawc_admin_meta_boxes.field_is_empty, "</option>\n                                                                    <option value=\"field_is_not_empty\">").concat(exprdawc_admin_meta_boxes.field_is_not_empty, "</option>\n                                                                    <option value=\"equals\">").concat(exprdawc_admin_meta_boxes.equals, "</option>\n                                                                    <option value=\"not_equals\">").concat(exprdawc_admin_meta_boxes.notEquals, "</option>\n                                                                    <option value=\"greater_than\">").concat(exprdawc_admin_meta_boxes.greaterThan, "</option>\n                                                                    <option value=\"less_than\">").concat(exprdawc_admin_meta_boxes.lessThan, "</option>\n                                                                </select>\n                                                                <input type=\"text\" name=\"extra_product_fields[").concat(this.fieldIndex, "][conditional_rules][0][0][value]\" class=\"exprdawc_input exprdawc_conditional_value\" placeholder=\"").concat(exprdawc_admin_meta_boxes.enterValue, "\" style=\"display:none;\" />\n                                                                <button type=\"button\" class=\"button remove_rule\"><i class=\"dashicons dashicons-trash\"></i></button>\n                                                                <button type=\"button\" class=\"button add_rule\">").concat(exprdawc_admin_meta_boxes.and, "</button>\n                                                            </div>\n                                                        </div>\n                                                    </div>\n                                                </div>\n                                            </td>                                            \n                                        </tr>\n                                    </tbody>\n                                </table>\n\n\n                                <!-- Text Area Option/Settings -->\n                                <table class=\"exprdawc_settings_table exprdawc_long_text_table\" style=\"display:none;\">\n                                    <tbody>\n                                        <tr>\n                                            <td>\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_long_text_rows_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.rows, "</label>\n                                                <input type=\"number\" id=\"exprdawc_long_text_rows_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_long_text_rows\" name=\"extra_product_fields[").concat(this.fieldIndex, "][rows]\" value=\"2\" />\n                                            </td>\n                                            <td>\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_long_text_cols_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.columns, "</label>\n                                                <input type=\"number\" id=\"exprdawc_long_text_cols_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_long_text_cols\" name=\"extra_product_fields[").concat(this.fieldIndex, "][cols]\" value=\"5\" />\n                                            </td>\n                                            <td>\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_long_text_default_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.default_value, "</label>\n                                                <textarea id=\"exprdawc_long_text_default_").concat(this.fieldIndex, "\" class=\"exprdawc_textarea\" rows=\"3\" cols=\"30\" placeholder=\"").concat(exprdawc_admin_meta_boxes.enter_default_text, "\" name=\"extra_product_fields[").concat(this.fieldIndex, "][default]\"></textarea>\n                                            </td>\n                                        </tr>\n                                    </tbody>\n                                </table>\n\n                                <!-- Text Option/Settings -->\n                                <table class=\"exprdawc_settings_table exprdawc_text_table\" style=\"display:none;\">\n                                    <tbody>\n                                        <tr>\n                                            <td>\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_min_length_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.min_length, "</label>\n                                                <input type=\"number\" id=\"exprdawc_text_min_length_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_text_min_length\" name=\"extra_product_fields[").concat(this.fieldIndex, "][minlength]\" value=\"0\" />\n                                            </td>\n                                            <td>\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_max_length_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.max_length, "</label>\n                                                <input type=\"number\" id=\"exprdawc_text_max_length_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_text_max_length\" name=\"extra_product_fields[").concat(this.fieldIndex, "][maxlength]\" value=\"255\" />\n                                            </td>\n                                            <td>\n                                                <label class=\"exprdawc_label\" for=\"exprdawc_text_default_").concat(this.fieldIndex, "\">").concat(exprdawc_admin_meta_boxes.default_value, "</label>\n                                                <input type=\"text\" id=\"exprdawc_text_default_").concat(this.fieldIndex, "\" class=\"exprdawc_input exprdawc_text_default\" placeholder=\"").concat(exprdawc_admin_meta_boxes.enter_default_text, "\" name=\"extra_product_fields[").concat(this.fieldIndex, "][default]\" />\n                                            </td>\n                                        </tr>\n                                    </tbody>\n                                </table>\n\n                                <table class=\"exprdawc_options_table\" style=\"display:none;\">\n                                    <thead>\n                                        <tr>\n                                            <th></th>\n                                            <th>").concat(exprdawc_admin_meta_boxes.option_label, "</th>\n                                            <th>").concat(exprdawc_admin_meta_boxes.option_value, "</th>\n                                            <th>").concat(exprdawc_admin_meta_boxes["default"], "</th>\n                                            <th>").concat(exprdawc_admin_meta_boxes.action, "</th>\n                                        </tr>\n                                    </thead>\n                                    <tbody>\n                                        <!-- Options will be dynamically added here -->\n                                    </tbody>\n                                    <tfoot>\n                                        <tr>\n                                            <td colspan=\"4\">\n                                                <button type=\"button\" class=\"button add_option\">").concat(exprdawc_admin_meta_boxes.add_option, "</button>\n                                            </td>\n                                        </tr>\n                                    </tfoot>\n                                </table>\n                                <p class=\"exprdawc_no_entry_message\" style=\"display: none;\">").concat(exprdawc_admin_meta_boxes.no_options, "</p>\n                            </td>\n                        </tr>\n                    </tbody>\n                </table>\n                </td>\n                </tr>\n                "));
     131        this.noEntryContent();
     132
     133        // Trigger change event to show the options.
     134        $('#exprdawc_attribute_type_' + this.fieldIndex).trigger('change');
     135      }
     136
     137      /**
     138       * Remove a custom field.
     139       * @param {*} e
     140       * @returns
     141       */
     142    }, {
     143      key: "removeCustomField",
     144      value: function removeCustomField(e) {
     145        if (confirm(exprdawc_admin_meta_boxes.confirm_delete)) {
     146          this.setDirty();
     147          $(e.currentTarget).closest('tr').next('.exprdawc_options').remove();
     148          $(e.currentTarget).closest('tr').remove();
     149          this.noEntryContent();
     150        }
     151        return false;
     152      }
     153
     154      /**
     155       * Toggle options.
     156       * @param {*} e
     157       */
     158    }, {
     159      key: "toggleOptions",
     160      value: function toggleOptions(e) {
     161        this.setDirty();
     162        var $row = $(e.currentTarget).closest('tr');
     163        var $optionsRow = $row.next('.exprdawc_options');
     164        var $optionsTable = $optionsRow.find('.exprdawc_options_table');
     165        var $placeholderText = $row.find('.exprdawc_placeholder');
     166        if ($(e.currentTarget).val() === 'radio' || $(e.currentTarget).val() === 'checkbox' || $(e.currentTarget).val() === 'select') {
     167          $placeholderText.prop('disabled', true);
     168          $optionsTable.show();
     169        } else {
     170          $placeholderText.prop('disabled', false);
     171          $optionsTable.hide();
     172        }
     173        if ($(e.currentTarget).val() === 'long_text') {
     174          $optionsRow.find('.exprdawc_long_text_table').show();
     175        } else {
     176          $optionsRow.find('.exprdawc_long_text_table').hide();
     177        }
     178        if ($(e.currentTarget).val() === 'text' || $(e.currentTarget).val() === 'email' || $(e.currentTarget).val() === 'number' || $(e.currentTarget).val() === 'date') {
     179          $optionsRow.find('.exprdawc_text_table').show();
     180        } else {
     181          $optionsRow.find('.exprdawc_text_table').hide();
     182        }
     183      }
     184
     185      /**
     186       * Toggle options table.
     187       * @param {*} e
     188       */
     189    }, {
     190      key: "toggleOptionsTable",
     191      value: function toggleOptionsTable(e) {
     192        var $icon = $(e.currentTarget);
     193        var $optionsRow = $icon.closest('tr').next('.exprdawc_options');
     194        $optionsRow.toggle();
     195        $icon.toggleClass('dashicons-arrow-down dashicons-arrow-up');
     196      }
     197
     198      /**
     199       * Add an option.
     200       * @param {*} e
     201       */
     202    }, {
     203      key: "addOption",
     204      value: function addOption(e) {
     205        this.setDirty();
     206        var $optionsTable = $(e.currentTarget).closest('.exprdawc_options_table');
     207        var optionIndex = $optionsTable.find('tbody tr').length;
     208        $optionsTable.find('tbody').append("\n                <tr>\n                    <td class=\"move\"><i class=\"dashicons dashicons-move\"></i></td>\n                    <td>\n                        <input type=\"text\" name=\"extra_product_fields[".concat(this.fieldIndex, "][options][").concat(optionIndex, "][label]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.option_label_placeholder, "\" />\n                    </td>\n                    <td>\n                        <input type=\"text\" name=\"extra_product_fields[").concat(this.fieldIndex, "][options][").concat(optionIndex, "][value]\" placeholder=\"").concat(exprdawc_admin_meta_boxes.option_value_placeholder, "\" />\n                    </td>\n                    <td>\n                        <input type=\"radio\" name=\"extra_product_fields[").concat(this.fieldIndex, "][default]\" value=\"").concat(optionIndex, "\" />\n                    </td>\n                    <td>\n                        <button type=\"button\" class=\"button remove_option\">").concat(exprdawc_admin_meta_boxes.remove, "</button>\n                    </td>\n                </tr>\n                "));
     209        this.checkOptions($optionsTable.closest('.exprdawc_options'));
     210      }
     211
     212      /**
     213       * Remove an option.
     214       * @param {*} e
     215       * @returns
     216       */
     217    }, {
     218      key: "removeOption",
     219      value: function removeOption(e) {
     220        if (confirm(exprdawc_admin_meta_boxes.confirm_delete)) {
     221          this.setDirty();
     222          $(e.currentTarget).closest('tr').remove();
     223          this.checkOptions($(e.currentTarget).closest('.exprdawc_options'));
     224        }
     225        return false;
     226      }
     227
     228      /**
     229       * Check options.
     230       * @param {*} $optionsRow
     231       */
     232    }, {
     233      key: "checkOptions",
     234      value: function checkOptions($optionsRow) {
     235        var $optionsTable = $optionsRow.find('.exprdawc_options_table tbody');
     236        var $noEntryMessage = $optionsRow.find('.exprdawc_no_entry_message');
     237        if ($optionsTable.find('tr').length === 0) {
     238          $noEntryMessage.show();
     239        } else {
     240          $noEntryMessage.hide();
     241        }
     242      }
     243
     244      /**
     245       * Export content.
     246       * @param {*} e
     247       * @returns
     248       */
     249    }, {
     250      key: "exportContent",
     251      value: function exportContent(e) {
     252        e.preventDefault();
     253        if (this.isDirty) {
     254          alert('Please save your changes before exporting.');
     255          return;
     256        }
     257        var $exportString = $('#exprdawc_export_string');
     258        var exportContent = $exportString.val();
     259        if (!exportContent) {
     260          alert("".concat(exprdawc_admin_meta_boxes.emptyExportMsg));
     261          return;
     262        }
     263        navigator.clipboard.writeText(exportContent).then(function () {
     264          alert("".concat(exprdawc_admin_meta_boxes.copySuccessMsg));
     265        }, function (err) {
     266          console.error('Could not copy text: ', err);
     267          alert("".concat(exprdawc_admin_meta_boxes.copyErrorMsg));
     268        });
     269      }
     270
     271      /**
     272       * Import content.
     273       * @param {*} e
     274       * @returns
     275       */
     276    }, {
     277      key: "importContent",
     278      value: function importContent(e) {
     279        e.preventDefault();
     280        var exportString = prompt(exprdawc_admin_meta_boxes.enterExportString);
     281        if (exportString) {
     282          var sureImportQuestion = confirm(exprdawc_admin_meta_boxes.sureImportQuestion);
     283          if (!sureImportQuestion) {
     284            return;
     285          }
     286          var productId = $('#post_ID').val();
     287          $.ajax({
     288            url: ajaxurl,
     289            method: 'POST',
     290            data: {
     291              action: 'exprdawc_import_custom_fields',
     292              product_id: productId,
     293              export_string: exportString,
     294              security: exprdawc_admin_meta_boxes.edit_exprdawc_nonce
     295            },
     296            success: function success(response) {
     297              if (response.success) {
     298                alert(exprdawc_admin_meta_boxes.importSuccessMsg);
     299                location.reload();
     300              } else {
     301                alert(exprdawc_admin_meta_boxes.importErrorMsg);
     302              }
     303            },
     304            error: function error() {
     305              alert(exprdawc_admin_meta_boxes.importErrorMsg);
     306            }
     307          });
     308        }
     309      }
     310
     311      /**
     312       * Set dirty.
     313       */
     314    }, {
     315      key: "setDirty",
     316      value: function setDirty() {
     317        this.isDirty = true;
     318        this.disableExportLink();
     319      }
     320
     321      /**
     322       * Disable export link.
     323       * @returns
     324       */
     325    }, {
     326      key: "disableExportLink",
     327      value: function disableExportLink() {
     328        if (this.isDirty) {
     329          $('.exprdawc-export').hide();
     330          return;
     331        }
     332      }
     333
     334      /**
     335       * No entry content.
     336       */
     337    }, {
     338      key: "noEntryContent",
     339      value: function noEntryContent() {
     340        var index = $('#exprdawc_field_body .exprdawc_attribute').length,
     341          $container = $('.exprdawc_no_entry_message'),
     342          $table_header = $('#exprdatawc_table_header'),
     343          $export_link = $('.exprdawc-export');
     344        if (index > 0) {
     345          $container.hide();
     346          $table_header.show();
     347          $export_link.show();
     348        } else {
     349          $container.show();
     350          $table_header.hide();
     351          $export_link.hide();
     352        }
     353      }
     354
     355      /**
     356       * Check autocomplete field.
     357       * @param {*} e
     358       */
     359    }, {
     360      key: "checkAutocompleteField",
     361      value: function checkAutocompleteField(e) {
     362        var $currentCheckbox = $(e.currentTarget);
     363        var isChecked = $currentCheckbox.is(':checked');
     364        if (isChecked) {
     365          var $otherChecked = $('.exprdawc_autocomplete_field').not($currentCheckbox).filter(':checked');
     366          if ($otherChecked.length > 0) {
     367            var confirmOverwrite = confirm(exprdawc_admin_meta_boxes.sureAnotherAutocompleCheckedQuestion);
     368            if (!confirmOverwrite) {
     369              $currentCheckbox.prop('checked', false);
     370              return;
     371            }
     372            $otherChecked.prop('checked', false);
     373          }
     374        }
     375      }
     376
     377      /**
     378       * Add a rule group.
     379       * @param {*} e
     380       */
     381    }, {
     382      key: "addRuleGroup",
     383      value: function addRuleGroup(e) {
     384        var $container = $(e.currentTarget).closest('.exprdawc_conditional_logic_table').find('.exprdawc_conditional_rules');
     385        var ruleGroupIndex = $container.find('.exprdawc_rule_group').length;
     386        var actualIndex = $(e.currentTarget).closest('.exprdawc_fields_table').data('index');
     387        var ruleGroupHtml = this.getRuleGroupHtml(actualIndex, ruleGroupIndex);
     388        $container.append(ruleGroupHtml);
     389      }
     390
     391      /**
     392       * Add a rule.
     393       * @param {*} e
     394       */
     395    }, {
     396      key: "addRule",
     397      value: function addRule(e) {
     398        var $ruleGroup = $(e.currentTarget).closest('.exprdawc_rule_group');
     399        var ruleGroupIndex = $ruleGroup.index();
     400        var actualIndex = $(e.currentTarget).closest('.exprdawc_fields_table').data('index');
     401        var ruleIndex = $ruleGroup.find('.exprdawc_rule').length;
     402        var ruleHtml = this.getRuleHtml(actualIndex, ruleGroupIndex, ruleIndex);
     403        $ruleGroup.append(ruleHtml);
     404      }
     405
     406      /**
     407       * Get rule group HTML.
     408       * @param {number} ruleGroupIndex
     409       * @returns {string}
     410       */
     411    }, {
     412      key: "getRuleGroupHtml",
     413      value: function getRuleGroupHtml(actualIndex, ruleGroupIndex) {
     414        return "\n            <div class=\"exprdawc_rule_group_container\">\n                <h2>".concat(exprdawc_admin_meta_boxes.or, "</h2>\n                <div class=\"exprdawc_rule_group\">\n                    ").concat(this.getRuleHtml(actualIndex, ruleGroupIndex, 0), "\n                </div>\n            </div>\n            ");
     415      }
     416
     417      /**
     418       * Get rule HTML.
     419       * @param {number} actualIndex
     420       * @param {number} ruleGroupIndex
     421       * @param {number} ruleIndex
     422       * @returns {string}
     423       */
     424    }, {
     425      key: "getRuleHtml",
     426      value: function getRuleHtml(actualIndex, ruleGroupIndex, ruleIndex) {
     427        return "\n            <div class=\"exprdawc_rule\">\n                <select name=\"extra_product_fields[".concat(actualIndex, "][conditional_rules][").concat(ruleGroupIndex, "][").concat(ruleIndex, "][field]\" class=\"exprdawc_input exprdawc_conditional_field\">\n                <option value=\"\">").concat(exprdawc_admin_meta_boxes.selectFieldNone, "</option>\n                ").concat(this.getAllFieldsOptions(), "\n                </select>\n                <select name=\"extra_product_fields[").concat(actualIndex, "][conditional_rules][").concat(ruleGroupIndex, "][").concat(ruleIndex, "][operator]\" class=\"exprdawc_input exprdawc_conditional_operator\">\n                    <option value=\"field_is_empty\">").concat(exprdawc_admin_meta_boxes.field_is_empty, "</option>\n                    <option value=\"field_is_not_empty\">").concat(exprdawc_admin_meta_boxes.field_is_not_empty, "</option>\n                    <option value=\"equals\">").concat(exprdawc_admin_meta_boxes.equals, "</option>\n                    <option value=\"not_equals\">").concat(exprdawc_admin_meta_boxes.notEquals, "</option>\n                    <option value=\"greater_than\">").concat(exprdawc_admin_meta_boxes.greaterThan, "</option>\n                    <option value=\"less_than\">").concat(exprdawc_admin_meta_boxes.lessThan, "</option>\n                </select>\n                <input type=\"text\" name=\"extra_product_fields[").concat(actualIndex, "][conditional_rules][").concat(ruleGroupIndex, "][").concat(ruleIndex, "][value]\" class=\"exprdawc_input exprdawc_conditional_value\" placeholder=\"").concat(exprdawc_admin_meta_boxes.enterValue, "\" style=\"display:none;\" />\n                <button type=\"button\" class=\"button remove_rule\"><i class=\"dashicons dashicons-trash\"></i></button>\n                <button type=\"button\" class=\"button add_rule\">+ ").concat(exprdawc_admin_meta_boxes.and, "</button>\n            </div>\n            ");
     428      }
     429
     430      /**
     431       * Toggle conditional value field visibility.
     432       * @param {*} e
     433       */
     434    }, {
     435      key: "toggleConditionalValueField",
     436      value: function toggleConditionalValueField(e) {
     437        var $operator = $(e.currentTarget);
     438        var $valueField = $operator.closest('.exprdawc_rule').find('.exprdawc_conditional_value');
     439        if ($operator.val() === 'field_changed' || $operator.val() === 'field_is_empty' || $operator.val() === 'field_is_not_empty') {
     440          $valueField.hide();
     441        } else {
     442          $valueField.show();
     443        }
     444      }
     445
     446      // Init all Rules toggleConditionalValueField
     447    }, {
     448      key: "toggleConditionalValueFieldAll",
     449      value: function toggleConditionalValueFieldAll() {
     450        $('.exprdawc_conditional_operator').each(function () {
     451          $(this).trigger('change');
     452        });
     453      }
     454
     455      /**
     456       * Remove a rule.
     457       * @param {*} e
     458       * @returns
     459       */
     460    }, {
     461      key: "removeRule",
     462      value: function removeRule(e) {
     463        if (confirm(exprdawc_admin_meta_boxes.confirm_delete_rule)) {
     464          var $ruleGroup = $(e.currentTarget).closest('.exprdawc_rule_group_container');
     465          $(e.currentTarget).closest('.exprdawc_rule').remove();
     466          if ($ruleGroup.find('.exprdawc_rule').length === 0) {
     467            $ruleGroup.remove();
     468          }
     469        }
     470        return false;
     471      }
     472
     473      /**
     474       * Get all fields options.
     475       * @returns
     476       */
     477    }, {
     478      key: "getAllFieldsOptions",
     479      value: function getAllFieldsOptions() {
     480        var options = '';
     481        $('#exprdawc_field_body tr.exprdawc_attribute').each(function () {
     482          var label = $(this).find('.exprdawc_attribute_input_name input').val();
     483          options += "<option value=\"".concat(label, "\">").concat(label, "</option>");
     484        });
     485        return options;
     486      }
     487
     488      /**
     489      * Enable or disable checkboxes based on a condition.
     490      */
     491    }, {
     492      key: "toggleConditionalTable",
     493      value: function toggleConditionalTable(e) {
     494        var checkbox = $(e.currentTarget);
     495        var $table_setting = $(e.currentTarget).closest('.exprdawc_options').find('.exprdawc_conditional_logic_table');
     496        if (checkbox.is(':checked')) {
     497          $table_setting.show();
     498        } else {
     499          $table_setting.hide();
     500        }
     501      }
     502    }]);
     503  }(); // Initialize the class.
     504  new ExprdawcMetaBoxesProduct();
    70505});
    71506
     
    76511  !*** ./src/assets/scss/admin-backend.scss ***!
    77512  \********************************************/
     513/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
     514
     515"use strict";
     516__webpack_require__.r(__webpack_exports__);
     517// extracted by mini-css-extract-plugin
     518
     519
     520/***/ }),
     521
     522/***/ "./src/assets/scss/forms.scss":
     523/*!************************************!*\
     524  !*** ./src/assets/scss/forms.scss ***!
     525  \************************************/
    78526/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
    79527
     
    172620/******/        var installedChunks = {
    173621/******/            "/assets/js/wc-meta-boxes-product": 0,
     622/******/            "assets/css/forms": 0,
    174623/******/            "assets/css/admin-backend": 0
    175624/******/        };
     
    222671/******/    // Load entry module and return exports
    223672/******/    // This entry module depends on other loaded chunks and execution need to be delayed
    224 /******/    __webpack_require__.O(undefined, ["assets/css/admin-backend"], () => (__webpack_require__("./src/assets/js/wc-meta-boxes-product.js")))
    225 /******/    var __webpack_exports__ = __webpack_require__.O(undefined, ["assets/css/admin-backend"], () => (__webpack_require__("./src/assets/scss/admin-backend.scss")))
     673/******/    __webpack_require__.O(undefined, ["assets/css/forms","assets/css/admin-backend"], () => (__webpack_require__("./src/assets/js/wc-meta-boxes-product.js")))
     674/******/    __webpack_require__.O(undefined, ["assets/css/forms","assets/css/admin-backend"], () => (__webpack_require__("./src/assets/scss/admin-backend.scss")))
     675/******/    var __webpack_exports__ = __webpack_require__.O(undefined, ["assets/css/forms","assets/css/admin-backend"], () => (__webpack_require__("./src/assets/scss/forms.scss")))
    226676/******/    __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
    227677/******/   
  • extra-product-data-for-woocommerce/trunk/extra-product-data-for-woocommerce.php

    r3198064 r3202511  
    33Plugin Name: Extra Product Data for WooCommerce
    44Description: Adds customizable input fields per product in WooCommerce, allowing users to enter extra details on the frontend.
    5 Version: 1.2.0
     5Version: 1.4.0
    66Author: Triopsi
    77Author URI: https://triopsi.dev
     
    4040require_once EXPRDAWC_CLASSES . 'class-exprdawc-main.php';
    4141
     42// Include Helper Class.
     43require_once EXPRDAWC_CLASSES . 'class-exprdawc-helper.php';
     44
    4245// Is WooCommerce active? Then not, display a notice.
    4346if ( ! tr_is_woocommerce_active() ) {
  • extra-product-data-for-woocommerce/trunk/readme.txt

    r3198064 r3202511  
    55Tested up to: 6.7
    66Requires PHP: 8.2
    7 Stable tag: 1.2.0
     7Stable tag: 1.4.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2828* Ideal for products that require user-specific information.
    2929* Easy to extend and customize for specific requirements.
     30* Added option to make fields conditional based on other field values.
     31* The admin can still edit the fields in the order overview.
    3032
    3133== Supported Fields ==
    3234The following field types are currently implemented:
    3335
    34     *   Text
    35     *   Textarea
    36     *   Number
    37     *   Email
    38     *   Yes/No Field
    39     *   Date
     36* Text
     37* Textarea
     38* Number
     39* Email
     40* Yes/No Field
     41* Date
     42* Select/options
     43* Radio Boxes
     44* Checboxes
    4045
    4146== Installation ==
     
    7883= 1.1.3 =
    7984* Update for the WordPress Library
    80 
    81 == Upgrade Notice ==
    82 
    83 = 1.0.0 =
    84 Initial release of Extra Product Data for WooCommerce.
  • extra-product-data-for-woocommerce/trunk/src/classes/class-exprdawc-admin-order.php

    r3198064 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     
    3131use WC_Product;
    3232
     33/**
     34 * Class Exprdawc_Admin_Order
     35 *
     36 * This class is responsible for the admin order page.
     37 *
     38 * @package Exprdawc
     39 */
    3340class Exprdawc_Admin_Order {
    3441
     
    7380        self::$order = $order;
    7481    }
    75 
    7682
    7783    /**
     
    106112        include EXPRDAWC_ADMIN_TEMPLATES_PATH . 'html-admin-order-edit-overview.php';
    107113    }
    108 
    109114
    110115    /**
     
    138143    }
    139144
    140 
    141145    /**
    142146     * Check if the current screen is one of the given screens.
     
    203207        // Generate the HTML for the form.
    204208        ob_start();
    205         include EXPRDAWC_ADMIN_TEMPLATES_PATH . 'html-admin-order-edit-form.php';
     209        foreach ( $custom_fields as $index => $field ) {
     210            $id           = strtolower( str_replace( ' ', '_', $field['label'] ) );
     211            $field_id     = 'exprdawc_custom_field_input[' . $item_id . '][' . $id . ']';
     212            $field_id_raw = 'field-input-' . $item_id . '-' . $id;
     213            Exprdawc_Helper::generate_input_field( $index, $field_id, $field_id_raw, $field, $extra_user_data );
     214        }
    206215        $html = ob_get_clean();
    207216
     
    271280        foreach ( $custom_fields as $index => $input_field_array ) {
    272281            $label_id                     = strtolower( str_replace( ' ', '_', $input_field_array['label'] ) );
    273             $extra_user_data[ $label_id ] = isset( $all_user_inputs[ $input_field_array['label'] ] ) ? $all_user_inputs[ $input_field_array['label'] ]->value : '';
     282            $old_value = isset( $all_user_inputs[ $input_field_array['label'] ] ) ? $all_user_inputs[ $input_field_array['label'] ]->value : '';
    274283
    275284            // Validate the input.
    276285            $field_value = '';
    277             if ( isset( $_POST['exprdawc_custom_field_input'][ $item_id ][ $label_id ] ) ) {
    278                 $field_value = sanitize_text_field( wp_unslash( $_POST['exprdawc_custom_field_input'][ $item_id ][ $label_id ] ) );
     286            $field = $_POST['exprdawc_custom_field_input'][ $item_id ][ $label_id ];
     287            if ( isset( $field ) ) {
     288                // Handle different field types
     289                if ( is_array( $field ) ) {
     290                    $field_value = array_map( 'sanitize_text_field', $field );
     291                } else {
     292                    $field_value = sanitize_text_field( $field );
     293                }
    279294            }
    280295
     
    305320                    }
    306321                    break;
     322                case 'radio':
     323                    $array_colum = array_column( $input_field_array['options'], 'value' );
     324                    $intersect = array_intersect( (array) $field_value, $array_colum );
     325                    if ( ! empty( $field_value ) && empty( $intersect ) ) {
     326                        wp_send_json_error( array( 'message' => sprintf( __( '%s is not a valid option.', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ) ) );
     327                    }
     328                    break;
     329                case 'checkbox':
     330                    $array_colum = array_column( $input_field_array['options'], 'value' );
     331                    $intersect = array_intersect( (array) $field_value, $array_colum );
     332                    if ( ! empty( $field_value ) && empty( $intersect ) ) {
     333                        wp_send_json_error( array( 'message' => sprintf( __( '%s is not a valid option.', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ) ) );
     334                    }
     335                    break;
     336                case 'select':
     337                    $array_colum = array_column( $input_field_array['options'], 'value' );
     338                    $intersect = array_intersect( (array) $field_value, $array_colum );
     339                    if ( ! empty( $field_value ) && empty( $intersect ) ) {
     340                        wp_send_json_error( array( 'message' => sprintf( __( '%s is not a valid option.', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ) ) );
     341                    }
     342                    break;
    307343                case 'long_text':
    308344                    $field_value = wp_kses_post( $field_value );
     
    315351
    316352            // Check for changes and add order note if there are any.
    317             if ( $field_value !== $extra_user_data[ $label_id ] ) {
    318                 $order->add_order_note( sprintf( __( '%1$s changed from "%2$s" to "%3$s".', 'extra-product-data-for-woocommerce' ), $input_field_array['label'], $extra_user_data[ $label_id ], $field_value ) );
     353            if ( is_array( $field_value ) ) {
     354                $field_value_str = implode( ', ', $field_value );
     355                $old_value_str = is_array( $old_value ) ? implode( ', ', $old_value ) : $old_value;
     356                if ( $field_value_str !== $old_value_str ) {
     357                    $order->add_order_note( sprintf( __( '%1$s changed from "%2$s" to "%3$s".', 'extra-product-data-for-woocommerce' ), $input_field_array['label'], $old_value_str, $field_value_str ) );
     358                }
     359            } else {
     360                if ( $field_value !== $old_value ) {
     361                    $order->add_order_note( sprintf( __( '%1$s changed from "%2$s" to "%3$s".', 'extra-product-data-for-woocommerce' ), $input_field_array['label'], $old_value, $field_value ) );
     362                }
     363            }
     364
     365            // if value are an array, than implode with comma.
     366            if ( is_array( $field_value ) ) {
     367                $field_value = implode( ', ', $field_value );
    319368            }
    320369
     
    323372        }
    324373
     374        // Save item meta data.
     375        $item->save_meta_data();
     376
    325377        // Save the item.
    326378        $item->save();
     379
     380        // Save Order
     381        $order->save();
    327382
    328383        // Generate the HTML for the form.
  • extra-product-data-for-woocommerce/trunk/src/classes/class-exprdawc-main.php

    r3198064 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     
    152152        if ( is_admin() ) {
    153153            wp_enqueue_style( 'exprdawc-backend-css', EXPRDAWC_ASSETS_CSS . 'admin-backend.css', array(), '1.0.0', 'all' );
     154            wp_enqueue_style( 'form-css', EXPRDAWC_ASSETS_CSS . 'forms.css', array(), '1.0.0', 'all' );
    154155        }
    155156    }
  • extra-product-data-for-woocommerce/trunk/src/classes/class-exprdawc-overview-cart.php

    r3195971 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     
    8585                            $cart_item_data[ $field_key ] = esc_url_raw( wp_unslash( $_POST[ $field_key ] ) );
    8686                            break;
     87                        case 'tel':
     88                            $cart_item_data[ $field_key ] = sanitize_text_field( wp_unslash( $_POST[ $field_key ] ) );
     89                            break;
     90                        case 'select':
     91                        case 'radio':
     92                        case 'checkbox':
     93                            if ( is_array( $_POST[ $field_key ] ) ) {
     94                                $cart_item_data[ $field_key ] = implode( ', ', array_map( 'sanitize_text_field', wp_unslash( $_POST[ $field_key ] ) ) );
     95                            } else {
     96                                $cart_item_data[ $field_key ] = sanitize_text_field( wp_unslash( $_POST[ $field_key ] ) );
     97                            }
     98                            break;
     99                        case 'date':
     100                            $cart_item_data[ $field_key ] = sanitize_text_field( wp_unslash( $_POST[ $field_key ] ) );
     101                            break;
    87102                        default:
    88103                            $cart_item_data[ $field_key ] = sanitize_text_field( wp_unslash( $_POST[ $field_key ] ) );
  • extra-product-data-for-woocommerce/trunk/src/classes/class-exprdawc-overview-order.php

    r3195971 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
  • extra-product-data-for-woocommerce/trunk/src/classes/class-exprdawc-product-page-backend.php

    r3198064 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     
    5252        // Add Scripts in head and footer
    5353        add_action( 'admin_enqueue_scripts', array( $this, 'exprdawc_show_general_tab' ) );
     54
     55        // Import custom fields.
     56        add_action( 'wp_ajax_exprdawc_import_custom_fields', array( $this, 'exprdawc_import_custom_fields' ) );
    5457    }
    5558
     
    7780     */
    7881    public function exprdawc_add_custom_product_fields() {
    79         global $post, $thepostid, $product_object;
     82        $custom_fields = get_post_meta( get_the_ID(), '_extra_product_fields', true );
    8083        include EXPRDAWC_TEMPLATES . 'html-tab-extra-attributes.php';
    8184    }
     
    8790     */
    8891    public function exprdawc_show_general_tab() {
    89         wp_enqueue_script( 'exprdawc-wc-meta-boxes-js', EXPRDAWC_ASSETS_JS . 'wc-meta-boxes-product.js', array(), '1.0.0', array( 'in_footer' => true ) );
     92        wp_enqueue_script( 'exprdawc-wc-meta-boxes-js', EXPRDAWC_ASSETS_JS . 'wc-meta-boxes-product.js', array( 'jquery', 'jquery-ui-sortable' ), '1.0.0', true );
    9093        wp_localize_script(
    9194            'exprdawc-wc-meta-boxes-js',
    9295            'exprdawc_admin_meta_boxes',
    9396            array(
    94                 'label_placeholder' => esc_html__( 'Name of the label', 'extra-product-data-for-woocommerce' ),
    95                 'short_text'        => esc_html__( 'Short Text', 'extra-product-data-for-woocommerce' ),
    96                 'long_text'         => esc_html__( 'Long Text', 'extra-product-data-for-woocommerce' ),
    97                 'email'             => esc_html__( 'Email', 'extra-product-data-for-woocommerce' ),
    98                 'number'            => esc_html__( 'Number', 'extra-product-data-for-woocommerce' ),
    99                 'date'              => esc_html__( 'Date', 'extra-product-data-for-woocommerce' ),
    100                 'yes_no'            => esc_html__( 'Yes/No', 'extra-product-data-for-woocommerce' ),
    101                 'placeholder_text'  => esc_html__( 'Placeholder Text', 'extra-product-data-for-woocommerce' ),
    102                 'help_text'         => esc_html__( 'Help Text', 'extra-product-data-for-woocommerce' ),
    103                 'remove'            => esc_html__( 'Remove', 'extra-product-data-for-woocommerce' ),
     97                'edit_exprdawc_nonce'                  => wp_create_nonce( 'edit_exprdawc_nonce' ),
     98                'label_placeholder'                    => esc_html__( 'Name of the label', 'extra-product-data-for-woocommerce' ),
     99                'short_text'                           => esc_html__( 'Short Text', 'extra-product-data-for-woocommerce' ),
     100                'long_text'                            => esc_html__( 'Long Text', 'extra-product-data-for-woocommerce' ),
     101                'email'                                => esc_html__( 'Email', 'extra-product-data-for-woocommerce' ),
     102                'number'                               => esc_html__( 'Number', 'extra-product-data-for-woocommerce' ),
     103                'date'                                 => esc_html__( 'Date', 'extra-product-data-for-woocommerce' ),
     104                'yes_no'                               => esc_html__( 'Yes/No', 'extra-product-data-for-woocommerce' ),
     105                'radio'                                => esc_html__( 'Radio Button', 'extra-product-data-for-woocommerce' ),
     106                'checkbox'                             => esc_html__( 'Checkbox', 'extra-product-data-for-woocommerce' ),
     107                'select'                               => esc_html__( 'Select', 'extra-product-data-for-woocommerce' ),
     108                'placeholder_text'                     => esc_html__( 'Placeholder Text', 'extra-product-data-for-woocommerce' ),
     109                'help_text'                            => esc_html__( 'Help Text', 'extra-product-data-for-woocommerce' ),
     110                'remove'                               => esc_html__( 'Remove', 'extra-product-data-for-woocommerce' ),
     111                'action'                               => esc_html__( 'Action', 'extra-product-data-for-woocommerce' ),
     112                'option_label'                         => esc_html__( 'Option Label', 'extra-product-data-for-woocommerce' ),
     113                'option_value'                         => esc_html__( 'Option Value', 'extra-product-data-for-woocommerce' ),
     114                'add_option'                           => esc_html__( 'Add Option', 'extra-product-data-for-woocommerce' ),
     115                'confirm_delete'                       => esc_html__( 'Are you sure you want to delete this field?', 'extra-product-data-for-woocommerce' ),
     116                'option_label_placeholder'             => esc_html__( 'Enter option label', 'extra-product-data-for-woocommerce' ),
     117                'option_value_placeholder'             => esc_html__( 'Enter option value', 'extra-product-data-for-woocommerce' ),
     118                'option_label_help'                    => esc_html__( 'This is the label for the option.', 'extra-product-data-for-woocommerce' ),
     119                'option_value_help'                    => esc_html__( 'This is the value for the option.', 'extra-product-data-for-woocommerce' ),
     120                'default_option_help'                  => esc_html__( 'Set as default option.', 'extra-product-data-for-woocommerce' ),
     121                'copySuccessMsg'                       => esc_html__( 'Copied to clipboard', 'extra-product-data-for-woocommerce' ),
     122                'copyErrorMsg'                         => esc_html__( 'Failed to copy', 'extra-product-data-for-woocommerce' ),
     123                'enterExportString'                    => esc_html__( 'Please enter the export string.', 'extra-product-data-for-woocommerce' ),
     124                'sureImportQuestion'                   => esc_html__( 'Are you sure you want to import the custom fields? All existing customs fields are delete.', 'extra-product-data-for-woocommerce' ),
     125                'importSuccessMsg'                     => esc_html__( 'Import successful', 'extra-product-data-for-woocommerce' ),
     126                'importErrorMsg'                       => esc_html__( 'Import failed', 'extra-product-data-for-woocommerce' ),
     127                'emptyExportMsg'                       => esc_html__( 'No custom fields to export', 'extra-product-data-for-woocommerce' ),
     128                'require_input'                        => esc_html__( 'Require input', 'extra-product-data-for-woocommerce' ),
     129                'enable_autofocus'                     => esc_html__( 'Autofocus this field on product page', 'extra-product-data-for-woocommerce' ),
     130                'placeholder_text_help'                => esc_html__( 'Placeholder Text', 'extra-product-data-for-woocommerce' ),
     131                'help_text'                            => esc_html__( 'Help Text', 'extra-product-data-for-woocommerce' ),
     132                'rows'                                 => esc_html__( 'Rows', 'extra-product-data-for-woocommerce' ),
     133                'collumns'                             => esc_html__( 'Collumns', 'extra-product-data-for-woocommerce' ),
     134                'default_value'                        => esc_html__( 'Default Value', 'extra-product-data-for-woocommerce' ),
     135                'min_length'                           => esc_html__( 'Min Length', 'extra-product-data-for-woocommerce' ),
     136                'max_length'                           => esc_html__( 'Max Length', 'extra-product-data-for-woocommerce' ),
     137                'enter_default_text'                   => esc_html__( 'Enter default text', 'extra-product-data-for-woocommerce' ),
     138                'sureAnotherAutocompleCheckedQuestion' => esc_html__( 'Another autocomplete field is already checked. Do you want to uncheck it?', 'extra-product-data-for-woocommerce' ),
     139                'autocomplete_function'                => esc_html__( 'Autocomplete Function', 'extra-product-data-for-woocommerce' ),
     140                'autocomplete_on'                      => esc_html__( 'On (default)', 'extra-product-data-for-woocommerce' ),
     141                'autocomplete_off'                     => esc_html__( 'Off', 'extra-product-data-for-woocommerce' ),
     142                'address_level1'                       => esc_html__( 'Address Level 1', 'extra-product-data-for-woocommerce' ),
     143                'address_level2'                       => esc_html__( 'Address Level 2', 'extra-product-data-for-woocommerce' ),
     144                'address_level3'                       => esc_html__( 'Address Level 3', 'extra-product-data-for-woocommerce' ),
     145                'address_level4'                       => esc_html__( 'Address Level 4', 'extra-product-data-for-woocommerce' ),
     146                'address_line1'                        => esc_html__( 'Address Line 1', 'extra-product-data-for-woocommerce' ),
     147                'address_line2'                        => esc_html__( 'Address Line 2', 'extra-product-data-for-woocommerce' ),
     148                'address_line3'                        => esc_html__( 'Address Line 3', 'extra-product-data-for-woocommerce' ),
     149                'bday'                                 => esc_html__( 'Birthday', 'extra-product-data-for-woocommerce' ),
     150                'bday_day'                             => esc_html__( 'Birthday Day', 'extra-product-data-for-woocommerce' ),
     151                'bday_month'                           => esc_html__( 'Birthday Month', 'extra-product-data-for-woocommerce' ),
     152                'bday_year'                            => esc_html__( 'Birthday Year', 'extra-product-data-for-woocommerce' ),
     153                'cc_additional_name'                   => esc_html__( 'Credit Card Additional Name', 'extra-product-data-for-woocommerce' ),
     154                'cc_csc'                               => esc_html__( 'Credit Card CSC', 'extra-product-data-for-woocommerce' ),
     155                'cc_exp'                               => esc_html__( 'Credit Card Expiry', 'extra-product-data-for-woocommerce' ),
     156                'cc_exp_month'                         => esc_html__( 'Credit Card Expiry Month', 'extra-product-data-for-woocommerce' ),
     157                'cc_exp_year'                          => esc_html__( 'Credit Card Expiry Year', 'extra-product-data-for-woocommerce' ),
     158                'cc_family_name'                       => esc_html__( 'Credit Card Family Name', 'extra-product-data-for-woocommerce' ),
     159                'cc_given_name'                        => esc_html__( 'Credit Card Given Name', 'extra-product-data-for-woocommerce' ),
     160                'cc_name'                              => esc_html__( 'Credit Card Name', 'extra-product-data-for-woocommerce' ),
     161                'cc_number'                            => esc_html__( 'Credit Card Number', 'extra-product-data-for-woocommerce' ),
     162                'cc_type'                              => esc_html__( 'Credit Card Type', 'extra-product-data-for-woocommerce' ),
     163                'country'                              => esc_html__( 'Country', 'extra-product-data-for-woocommerce' ),
     164                'country_name'                         => esc_html__( 'Country Name', 'extra-product-data-for-woocommerce' ),
     165                'email'                                => esc_html__( 'Email', 'extra-product-data-for-woocommerce' ),
     166                'language'                             => esc_html__( 'Language', 'extra-product-data-for-woocommerce' ),
     167                'photo'                                => esc_html__( 'Photo', 'extra-product-data-for-woocommerce' ),
     168                'postal_code'                          => esc_html__( 'Postal Code', 'extra-product-data-for-woocommerce' ),
     169                'sex'                                  => esc_html__( 'Sex', 'extra-product-data-for-woocommerce' ),
     170                'street_address'                       => esc_html__( 'Street Address', 'extra-product-data-for-woocommerce' ),
     171                'tel'                                  => esc_html__( 'Telephone', 'extra-product-data-for-woocommerce' ),
     172                'tel_area_code'                        => esc_html__( 'Telephone Area Code', 'extra-product-data-for-woocommerce' ),
     173                'tel_country_code'                     => esc_html__( 'Telephone Country Code', 'extra-product-data-for-woocommerce' ),
     174                'tel_extension'                        => esc_html__( 'Telephone Extension', 'extra-product-data-for-woocommerce' ),
     175                'tel_local'                            => esc_html__( 'Telephone Local', 'extra-product-data-for-woocommerce' ),
     176                'tel_local_prefix'                     => esc_html__( 'Telephone Local Prefix', 'extra-product-data-for-woocommerce' ),
     177                'tel_local_suffix'                     => esc_html__( 'Telephone Local Suffix', 'extra-product-data-for-woocommerce' ),
     178                'tel_national'                         => esc_html__( 'Telephone National', 'extra-product-data-for-woocommerce' ),
     179                'transaction_amount'                   => esc_html__( 'Transaction Amount', 'extra-product-data-for-woocommerce' ),
     180                'transaction_currency'                 => esc_html__( 'Transaction Currency', 'extra-product-data-for-woocommerce' ),
     181                'url'                                  => esc_html__( 'URL', 'extra-product-data-for-woocommerce' ),
     182                'and'                                  => esc_html__( 'AND', 'extra-product-data-for-woocommerce' ),
     183                'or'                                   => esc_html__( 'OR', 'extra-product-data-for-woocommerce' ),
     184                'selectFieldNone'                      => esc_html__( 'None', 'extra-product-data-for-woocommerce' ),
     185                'equals'                               => esc_html__( 'Equals', 'extra-product-data-for-woocommerce' ),
     186                'notEquals'                            => esc_html__( 'Not equals', 'extra-product-data-for-woocommerce' ),
     187                'greaterThan'                          => esc_html__( 'Greater than', 'extra-product-data-for-woocommerce' ),
     188                'lessThan'                             => esc_html__( 'Less than', 'extra-product-data-for-woocommerce' ),
     189                'enterValue'                           => esc_html__( 'Enter value', 'extra-product-data-for-woocommerce' ),
     190                'confirm_delete_rule'                  => esc_html__( 'Are you sure you want to delete this rule?', 'extra-product-data-for-woocommerce' ),
     191                'field_changed'                        => esc_html__( 'Field changed', 'extra-product-data-for-woocommerce' ),
     192                'field_is_empty'                       => esc_html__( 'Field is empty', 'extra-product-data-for-woocommerce' ),
     193                'field_is_not_empty'                   => esc_html__( 'Field is not empty', 'extra-product-data-for-woocommerce' ),
     194                'enable_conditional_logic'             => esc_html__( 'Enable conditional logic', 'extra-product-data-for-woocommerce' ),
     195                'conditionals'                         => esc_html__( 'Conditionals', 'extra-product-data-for-woocommerce' ),
     196                'conditionals_description'             => esc_html__( 'Only show this field when conditional rules are true.', 'extra-product-data-for-woocommerce' ),
    104197            )
    105198        );
     
    125218
    126219                    // SANITIZE: Clean the input data
    127                     $label            = sanitize_text_field( $field['label'] );
    128                     $type             = sanitize_text_field( $field['type'] );
    129                     $required         = isset( $field['required'] ) ? 1 : 0;
    130                     $placeholder_text = sanitize_text_field( $field['placeholder_text'] );
    131                     $help_text        = sanitize_text_field( $field['help_text'] );
     220                    $label             = sanitize_text_field( $field['label'] );
     221                    $type              = sanitize_text_field( $field['type'] );
     222                    $required          = isset( $field['required'] ) ? 1 : 0;
     223                    $conditional_logic = isset( $field['conditional_logic'] ) ? 1 : 0;
     224                    $placeholder_text  = sanitize_text_field( $field['placeholder_text'] );
     225                    $help_text         = sanitize_text_field( $field['help_text'] );
     226                    $autocomplete      = isset( $field['autocomplete'] ) ? sanitize_text_field( $field['autocomplete'] ) : '';
     227                    $autofocus         = isset( $field['autofocus'] ) ? true : false;
     228                    $index           = isset( $field['index'] ) ? absint( $field['index'] ) : 0;
     229
     230                    // Conditional Logic
     231                    if ( isset( $field['conditional_rules'] ) ) {
     232                        foreach ( $field['conditional_rules'] as $rule_group ) {
     233                            foreach ( $rule_group as $rule ) {
     234                                $rule['field']    = sanitize_text_field( $rule['field'] );
     235                                $rule['operator'] = sanitize_text_field( $rule['operator'] );
     236                                $rule['value']    = sanitize_text_field( $rule['value'] );
     237                            }
     238                        }
     239                        $conditional_logic_rules = $field['conditional_rules'];
     240                    } else {
     241                        $conditional_logic_rules = array();
     242                        $conditional_logic       = 0;
     243                    }
     244
     245                    // For Checbox, Radio and Select
     246                    $options = isset( $field['options'] ) && is_array( $field['options'] ) ? array_map(
     247                        function ( $option ) {
     248                            return array(
     249                                'label' => sanitize_text_field( $option['label'] ),
     250                                'value' => sanitize_text_field( $option['value'] ),
     251                            );
     252                        },
     253                        $field['options']
     254                    ) : array();
     255
     256                    $default = isset( $field['default'] ) ? sanitize_text_field( $field['default'] ) : '';
     257
     258                    // For Text
     259                    $minlength = isset( $field['minlength'] ) ? absint( $field['minlength'] ) : 0;
     260                    $maxlength = isset( $field['maxlength'] ) ? absint( $field['maxlength'] ) : 0;
     261
     262                    // For Textarea
     263                    $rows = isset( $field['rows'] ) ? absint( $field['rows'] ) : 0;
     264                    $cols = isset( $field['cols'] ) ? absint( $field['cols'] ) : 0;
    132265
    133266                    // VALIDATE: Ensure the data meets the required criteria
     
    145278                    }
    146279                    return array(
    147                         'label'            => $label,
    148                         'type'             => $type,
    149                         'required'         => $required,
    150                         'placeholder_text' => $placeholder_text,
    151                         'help_text'        => $help_text,
     280                        'label'             => $label,
     281                        'type'              => $type,
     282                        'required'          => $required,
     283                        'conditional_logic' => $conditional_logic,
     284                        'placeholder_text'  => $placeholder_text,
     285                        'help_text'         => $help_text,
     286                        'options'           => $options,
     287                        'default'           => $default,
     288                        'minlength'         => $minlength,
     289                        'maxlength'         => $maxlength,
     290                        'rows'              => $rows,
     291                        'cols'              => $cols,
     292                        'autocomplete'      => $autocomplete,
     293                        'autofocus'         => $autofocus,
     294                        'conditional_rules' => $conditional_logic_rules,
     295                        'index'             => $index,
    152296                    );
    153297                },
     
    162306        }
    163307    }
     308
     309    /**
     310     * Import custom fields.
     311     *
     312     * This function is responsible for importing custom fields from a JSON string
     313     * and saving them to the product meta data.
     314     */
     315    public function exprdawc_import_custom_fields() {
     316
     317        // SECURITY: Check if the request is valid
     318        check_ajax_referer( 'edit_exprdawc_nonce', 'security' );
     319
     320        // VALIDATE: Ensure the product ID is set
     321        if ( ! current_user_can( 'edit_product', $_POST['product_id'] ) ) {
     322            wp_send_json_error( 'You do not have permission to edit this product.' );
     323        }
     324
     325        // VALIDATE: Ensure the product ID is valid
     326        $product_id = intval( $_POST['product_id'] );
     327
     328        // VALIDATE: Ensure the product ID is valid
     329        if ( $product_id === 0 ) {
     330            wp_send_json_error( 'Invalid product ID.' );
     331        }
     332
     333        // Get Product.
     334        $product = wc_get_product( $product_id );
     335        if ( ! $product ) {
     336            wp_send_json_error( 'Invalid product ID.' );
     337        }
     338
     339        // UNSLASH: Remove slashes from the input data
     340        $export_string = wp_unslash( $_POST['export_string'] );
     341
     342        // SANITIZE: Clean the input data
     343        $custom_fields = json_decode( $export_string, true );
     344
     345        // Validate JSON string
     346        if ( json_last_error() !== JSON_ERROR_NONE ) {
     347            wp_send_json_error( 'Invalid JSON string.' );
     348        }
     349
     350        // Save the sanitized and validated data
     351        update_post_meta( $product_id, '_extra_product_fields', $custom_fields );
     352
     353        // Return success message.
     354        wp_send_json_success();
     355    }
    164356}
  • extra-product-data-for-woocommerce/trunk/src/classes/class-exprdawc-product-page-fronted.php

    r3195971 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     
    2626
    2727namespace Triopsi\Exprdawc;
     28
     29if ( ! defined( 'ABSPATH' ) ) {
     30    exit;
     31}
    2832
    2933/**
     
    5660        add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'exprdawc_display_custom_fields_on_product_page' ) );
    5761        add_filter( 'woocommerce_add_to_cart_validation', array( $this, 'exprdawc_validate_custom_fields' ), 10, 3 );
     62
     63        // Add Frontend CSS for custom fields.
     64        add_action( 'wp_enqueue_scripts', array( $this, 'exprdawc_add_frontend_styles_scripts' ) );
     65    }
     66
     67    /**
     68     * Enqueues the frontend styles for the custom fields.
     69     *
     70     * This function enqueues the frontend styles for the custom fields on the product page.
     71     * The styles are enqueued only if the current page is a product page.
     72     *
     73     * @return void
     74     */
     75    public function exprdawc_add_frontend_styles_scripts() {
     76        if ( is_product() ) {
     77            wp_enqueue_style( 'form-css', EXPRDAWC_ASSETS_CSS . 'forms.css', array(), '1.0.0', 'all' );
     78
     79            // Enqueue the wc-conditional-rules-js script.
     80            wp_enqueue_script( 'wc-conditional-rules-js', EXPRDAWC_ASSETS_JS . 'wc-conditional-rules-js.js', array( 'jquery' ), '1.0.0', true );
     81        }
    5882    }
    5983
     
    77101            wp_nonce_field( 'exprdawc_save_custom_field', 'exprdawc_nonce' );
    78102            foreach ( $custom_fields as $index => $field ) {
    79                 $field_type = $field['type'];
    80                 $field_args = array(
    81                     'class'       => array( 'form-row-wide', $field['required'] ? 'exprdawc-required' : '' ),
    82                     'label'       => esc_html( $field['label'] ),
    83                     'required'    => ! empty( $field['required'] ),
    84                     'placeholder' => $field['placeholder_text'],
    85                     'description' => $field['help_text'],
    86                 );
    87 
    88                 switch ( $field_type ) {
    89                     case 'long_text':
    90                         $field_args['type'] = 'textarea';
    91                         break;
    92                     case 'date':
    93                         $field_args['type'] = 'date';
    94                         break;
    95                     case 'email':
    96                         $field_args['type'] = 'email';
    97                         break;
    98                     case 'number':
    99                         $field_args['type'] = 'number';
    100                         break;
    101                     case 'yes-no':
    102                         $field_args['type']    = 'select';
    103                         $field_args['options'] = array(
    104                             'yes' => __( 'Yes', 'extra-product-data-for-woocommerce' ),
    105                             'no'  => __( 'No', 'extra-product-data-for-woocommerce' ),
    106                         );
    107                         break;
    108                     default:
    109                         $field_args['type'] = 'text';
    110                         break;
    111                 }
    112 
    113                 woocommerce_form_field( 'extra_user_data_' . $index, $field_args );
     103                $id           = strtolower( str_replace( ' ', '_', $field['label'] ) );
     104                $field_id     = 'extra_user_data_' . esc_attr( $index );
     105                $field_id_raw = 'field-input-' . $index . '-' . $id;
     106                Exprdawc_Helper::generate_input_field( $index, $field_id, $field_id_raw, $field );
    114107            }
    115108            echo '</div>';
     
    133126
    134127        if ( ! empty( $custom_fields ) ) {
    135             foreach ( $custom_fields as $index => $field ) {
     128            foreach ( $custom_fields as $index => $input_field_array ) {
    136129                $field_value = isset( $_POST[ 'extra_user_data_' . $index ] ) ? $_POST[ 'extra_user_data_' . $index ] : '';
    137                 if ( ! empty( $field['required'] ) && empty( $field_value ) ) {
     130
     131                // Handle different field types
     132                if ( is_array( $field_value ) ) {
     133                    $field_value = array_map( 'sanitize_text_field', $field_value );
     134                } else {
     135                    $field_value = sanitize_text_field( $field_value );
     136                }
     137
     138                if ( ! empty( $input_field_array['required'] ) && empty( $field_value ) ) {
    138139                    /* translators: %s: field label */
    139                     wc_add_notice( sprintf( esc_html__( '%s is a required field.', 'extra-product-data-for-woocommerce' ), $field['label'] ), 'error' );
     140                    wc_add_notice( sprintf( esc_html__( '%s is a required field.', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ), 'error' );
    140141                    $passed = false;
    141142                }
    142143
    143144                // Additional validation based on field type
    144                 switch ( $field['type'] ) {
     145                switch ( $input_field_array['type'] ) {
    145146                    case 'email':
    146147                        if ( ! empty( $field_value ) && ! is_email( $field_value ) ) {
    147148                            /* translators: %s: field label */
    148                             wc_add_notice( sprintf( esc_html__( '%s is not a valid email address.', 'extra-product-data-for-woocommerce' ), $field['label'] ), 'error' );
     149                            wc_add_notice( sprintf( esc_html__( '%s is not a valid email address.', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ), 'error' );
    149150                            $passed = false;
    150151                        }
     
    153154                        if ( ! empty( $field_value ) && ! is_numeric( $field_value ) ) {
    154155                            /* translators: %s: field label */
    155                             wc_add_notice( sprintf( esc_html__( '%s must be a number.', 'extra-product-data-for-woocommerce' ), $field['label'] ), 'error' );
     156                            wc_add_notice( sprintf( esc_html__( '%s must be a number.', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ), 'error' );
    156157                            $passed = false;
    157158                        }
     
    160161                        if ( ! empty( $field_value ) && ! strtotime( $field_value ) ) {
    161162                            /* translators: %s: field label */
    162                             wc_add_notice( sprintf( esc_html__( '%s is not a valid date.', 'extra-product-data-for-woocommerce' ), $field['label'] ), 'error' );
     163                            wc_add_notice( sprintf( esc_html__( '%s is not a valid date.', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ), 'error' );
    163164                            $passed = false;
    164165                        }
     
    167168                        if ( ! empty( $field_value ) && ! in_array( $field_value, array( 'yes', 'no' ) ) ) {
    168169                            /* translators: %s: field label */
    169                             wc_add_notice( sprintf( esc_html__( '%s must be either "Yes" or "No".', 'extra-product-data-for-woocommerce' ), $field['label'] ), 'error' );
     170                            wc_add_notice( sprintf( esc_html__( '%s must be either "Yes" or "No".', 'extra-product-data-for-woocommerce' ), $input_field_array['label'] ), 'error' );
     171                            $passed = false;
     172                        }
     173                        break;
     174                    case 'radio':
     175                        $array_colum = array_column( $input_field_array['options'], 'value' );
     176                        $intersect   = array_intersect( (array) $field_value, $array_colum );
     177                        if ( ! empty( $field_value ) && empty( $intersect ) ) {
     178                            wc_add_notice( esc_html__( 'Invalid option selected for radio button.', 'extra-product-data-for-woocommerce' ), 'error' );
     179                            $passed = false;
     180                        }
     181                        break;
     182                    case 'checkbox':
     183                        $array_colum = array_column( $input_field_array['options'], 'value' );
     184                        $intersect   = array_intersect( (array) $field_value, $array_colum );
     185                        if ( ! empty( $field_value ) && empty( $intersect ) ) {
     186                            wc_add_notice( esc_html__( 'Invalid option selected for checkbox.', 'extra-product-data-for-woocommerce' ), 'error' );
     187                            $passed = false;
     188                        }
     189                        break;
     190                    case 'select':
     191                        $array_colum = array_column( $input_field_array['options'], 'value' );
     192                        $intersect   = array_intersect( (array) $field_value, $array_colum );
     193                        if ( ! empty( $field_value ) && empty( $intersect ) ) {
     194                            wc_add_notice( esc_html__( 'Invalid option selected for select field.', 'extra-product-data-for-woocommerce' ), 'error' );
    170195                            $passed = false;
    171196                        }
  • extra-product-data-for-woocommerce/trunk/src/functions.php

    r3195971 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
  • extra-product-data-for-woocommerce/trunk/src/lib/core.php

    r3195971 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     
    2727namespace Triopsi\Exprdawc;
    2828
     29/**
     30 * Class Autoloader
     31 *
     32 * This class is responsible for autoloading classes from the classes directory.
     33 *
     34 * @package Exprdawc
     35 */
    2936class Autoloader {
    3037
  • extra-product-data-for-woocommerce/trunk/src/templates/view/admin/html-admin-order-edit-overview-js.php

    r3198064 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
    1010 */
     11if ( ! defined( 'ABSPATH' ) ) {
     12    exit;
     13}
    1114?>
    1215<script type="text/template" id="tmpl-wc-modal-edit-exprdawc">
  • extra-product-data-for-woocommerce/trunk/src/templates/view/admin/html-admin-order-edit-overview.php

    r3198064 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
  • extra-product-data-for-woocommerce/trunk/src/templates/view/fields/checkbox.php

    r3202510 r3202511  
    2525 */
    2626
    27 woocommerce_form_field( $field_args['id'], $field_args, $field_args['value'] );
    28 ?>
     27if ( ! defined( 'ABSPATH' ) ) {
     28    exit;
     29}
     30
     31if ( isset( $field_args['options'] ) && is_array( $field_args['options'] ) ) {
     32    echo '<label class="' . esc_attr( implode( ' ', $field_args['label_class'] ) ) . '"
     33    ' . implode( ' ', $custom_attributes ) . '>' . esc_html( $field_args['label'] ) . $required_string . '</label>';
     34    foreach ( $field_args['options'] as $option_value => $option_label ) {
     35        $checked = in_array( $option_value, (array) explode( ', ', $field_args['value'] ) ) ? 'checked' : '';
     36        echo '<div class="exprdawc-checkbox-option">';
     37        echo '<input type="checkbox"
     38            id="' . esc_attr( $field_args['id'] . '_' . $option_value ) . '"
     39            name="' . esc_attr( $field_args['name'] ) . '[]"
     40            value="' . esc_attr( $option_value ) . '" ' . $checked . ( $field_args['required'] ? ' aria-required="true"' : '' ) . '
     41            class="checkbox ' . esc_attr( implode( ' ', $field_args['input_class'] ) ) . '"
     42            ' . implode( ' ', $custom_attributes ) . '/>';
     43
     44        echo '<label for="' . esc_attr( $field_args['id'] . '_' . $option_value ) . '" class="exprdawc-label-checkbox">' . esc_html( $option_label ) . '</label>';
     45        echo '</div>';
     46    }
     47    if ( isset( $field_args['unchecked_value'] ) ) {
     48        echo '<input type="hidden" name="' . esc_attr( $field_args['id'] ) . '[]" value="' . esc_attr( $field_args['unchecked_value'] ) . '" />';
     49    }
     50    if ( ! empty( $field_args['description'] ) ) {
     51        echo '<span id="' . esc_attr( $field_args['id'] ) . '_description" class="' . esc_attr( implode( ' ', $field_args['description_class'] ) ) . '">' . esc_html( $field_args['description'] ) . '</span>';
     52    }
     53}
  • extra-product-data-for-woocommerce/trunk/src/templates/view/fields/custom-field-end.php

    r3198064 r3202511  
     1<?php
     2/**
     3 * Created on Tue Nov 26 2024
     4 *
     5 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
     6 *
     7 * @package Extra Product Data for WooCommerce
     8 * @author Daniel Drevermann <info@triopsi.com>
     9 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     10 *
     11 * This program is free software: you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation, either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * This program is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
     23 *
     24 * This file is part of the development of WordPress plugins.
     25 */
     26
     27if ( ! defined( 'ABSPATH' ) ) {
     28    exit;
     29}
     30
     31echo '</div>';
     32echo '<p></p>';
  • extra-product-data-for-woocommerce/trunk/src/templates/view/fields/custom-field-start.php

    r3198064 r3202511  
     1<?php
     2/**
     3 * Created on Tue Nov 26 2024
     4 *
     5 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
     6 *
     7 * @package Extra Product Data for WooCommerce
     8 * @author Daniel Drevermann <info@triopsi.com>
     9 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     10 *
     11 * This program is free software: you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation, either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * This program is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
     23 *
     24 * This file is part of the development of WordPress plugins.
     25 */
     26
     27if ( ! defined( 'ABSPATH' ) ) {
     28    exit;
     29}
     30echo '<div id="' . esc_attr( $field_args['id_attr'] ) . '-wrapper-field" class="' . esc_attr( implode( ' ', $field_args['wrapper_class'] ) ) . '">';
  • extra-product-data-for-woocommerce/trunk/src/templates/view/fields/radio.php

    r3202510 r3202511  
    2525 */
    2626
    27  woocommerce_form_field( $field_args['id'], $field_args, $field_args['value'] );
    28 ?>
     27if ( ! defined( 'ABSPATH' ) ) {
     28    exit;
     29}
     30
     31if ( isset( $field_args['options'] ) && is_array( $field_args['options'] ) ) {
     32    echo '<label class="' . esc_attr( implode( ' ', $field_args['label_class'] ) ) . '">' . esc_html( $field_args['label'] ) . $required_string . '</label>';
     33    foreach ( $field_args['options'] as $option_value => $option_label ) {
     34        $checked = in_array( $option_value, (array) $field_args['value'] ) ? 'checked' : '';
     35        echo '<div class="exprdawc-checkbox-option">';
     36
     37        echo '<input type="radio"
     38            id="' . esc_attr( $field_args['id'] . '_' . $option_value ) . '"
     39            name="' . esc_attr( $field_args['name'] ) . '[]"
     40            value="' . esc_attr( $option_value ) . '" ' . $checked . ( $field_args['required'] ? ' aria-required="true"' : '' ) . '
     41            class="radio ' . esc_attr( implode( ' ', $field_args['input_class'] ) ) . '"
     42            ' . implode( ' ', $custom_attributes ) . '/>';
     43
     44        echo '<label for="' . esc_attr( $field_args['id'] . '_' . $option_value ) . '" class="exprdawc-label-checkbox">' . esc_html( $option_label ) . '</label>';
     45        echo '</div>';
     46    }
     47    if ( ! empty( $field_args['description'] ) ) {
     48        echo '<span id="' . esc_attr( $field_args['id'] ) . '_description" class="' . esc_attr( implode( ' ', $field_args['description_class'] ) ) . '">' . esc_html( $field_args['description'] ) . '</span>';
     49    }
     50}
  • extra-product-data-for-woocommerce/trunk/src/templates/view/fields/select.php

    r3198064 r3202511  
    2525 */
    2626
    27 $field_args['custom_attributes'] = array(
    28     'style' => 'display: block;'
     27if ( ! defined( 'ABSPATH' ) ) {
     28    exit;
     29}
    2930
    30 );
    31 woocommerce_form_field( $field_args['id'], $field_args, $field_args['value'] );
     31if ( isset( $field_args['options'] ) && is_array( $field_args['options'] ) ) {
     32    echo '<label for="' . esc_attr( $field_args['id_attr'] ) . '" class="' . esc_attr( implode( ' ', $field_args['label_class'] ) ) . '">' . esc_html( $field_args['label'] ) . $required_string . '</label>';
     33    echo '<select class="select ' . esc_attr( implode( ' ', $field_args['input_class'] ) ) . '"
     34    id="' . esc_attr( $field_args['id_attr'] ) . '"
     35    name="' . esc_attr( $field_args['name'] ) . '"
     36    ' . implode( ' ', $custom_attributes ) . '>';
     37    foreach ( $field_args['options'] as $option_value => $option_label ) {
     38        $selected = selected( $field_args['value'], $option_value, false );
     39        echo '<option value="' . esc_attr( $option_value ) . '" ' . $selected . '>' . esc_html( $option_label ) . '</option>';
     40    }
     41    echo '</select>';
     42    if ( ! empty( $field_args['description'] ) ) {
     43        echo '<span id="' . esc_attr( $field_args['id'] ) . '_description" class="' . esc_attr( implode( ' ', $field_args['description_class'] ) ) . '">' . esc_html( $field_args['description'] ) . '</span>';
     44    }
     45}
  • extra-product-data-for-woocommerce/trunk/src/templates/view/fields/text.php

    r3198064 r3202511  
    2525 */
    2626
    27 woocommerce_form_field( $field_args['id'], $field_args, $field_args['value'] );
     27if ( ! defined( 'ABSPATH' ) ) {
     28    exit;
     29}
     30echo '<label for="' . esc_attr( $field_args['id_attr'] ) . '" class="' . esc_attr( implode( ' ', $field_args['label_class'] ) ) . '">' . esc_html( $field_args['label'] ) . $required_string . '</label>';
     31echo '<span class="' . esc_attr( implode( ' ', $field_args['input_wrapper_class'] ) ) . '">';
     32echo '<input type="' . esc_attr( $field_args['type'] ) . '"
     33    class="input-text ' . esc_attr( implode( ' ', $field_args['input_class'] ) ) . '"
     34    name="' . esc_attr( $field_args['name'] ) . '"
     35    id="' . esc_attr( $field_args['id_attr'] ) . '"
     36    placeholder="' . esc_attr( $field_args['placeholder'] ) . '"
     37    value="' . esc_attr( $field_args['value'] ) . '"
     38    ' . implode( ' ', $custom_attributes ) . ' />';
     39
     40if ( ! empty( $field_args['description'] ) ) {
     41    echo '<span id="' . esc_attr( $field_args['id'] ) . '_description" class="' . esc_attr( implode( ' ', $field_args['description_class'] ) ) . '">' . esc_html( $field_args['description'] ) . '</span>';
     42}
     43echo '</span>';
  • extra-product-data-for-woocommerce/trunk/src/templates/view/fields/textarea.php

    r3198064 r3202511  
    2424 * This file is part of the development of WordPress plugins.
    2525 */
     26if ( ! defined( 'ABSPATH' ) ) {
     27    exit;
     28}
    2629
    27  woocommerce_form_field( $field_args['id'], $field_args, $field_args['value'] );
    28 ?>
     30echo '<label for="' . esc_attr( $field_args['id_attr'] ) . '" class="' . esc_attr( implode( ' ', $field_args['label_class'] ) ) . '">' . esc_html( $field_args['label'] ) . $required_string . '</label>';
     31echo '<span class="' . esc_attr( implode( ' ', $field_args['input_wrapper_class'] ) ) . '">';
     32echo '<textarea
     33    name="' . esc_attr( $field_args['name'] ) . '"
     34    class="input-text ' . esc_attr( implode( ' ', $field_args['input_class'] ) ) . '"
     35    id="' . esc_attr( $field_args['id_attr'] ) . '"
     36    placeholder="' . esc_attr( $field_args['placeholder'] ) . '" ' .
     37    ( empty( $field_args['custom_attributes']['rows'] ) ? ' rows="2"' : '' ) .
     38    ( empty( $field_args['custom_attributes']['cols'] ) ? ' cols="5"' : '' ) .
     39    implode( ' ', $custom_attributes ) . '>' .
     40    esc_textarea( $field_args['value'] ) .
     41    '</textarea>';
     42if ( ! empty( $field_args['description'] ) ) {
     43    echo '<span id="' . esc_attr( $field_args['id'] ) . '_description" class="' . esc_attr( implode( ' ', $field_args['description_class'] ) ) . '">' . esc_html( $field_args['description'] ) . '</span>';
     44}
     45echo '</span>';
  • extra-product-data-for-woocommerce/trunk/src/templates/view/html-tab-extra-attributes-fields.php

    r3195971 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    9  * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     9 * @copyright (c) 2024, IT-Dienstleistungen Drevermann
    1010 *
    1111 * This program is free software: you can redistribute it and/or modify
     
    2828}
    2929?>
    30 <tr class="exprdawc_attribute">
    31     <td class="move"><i class="dashicons dashicons-move"></i></td>
    32     <td class="exprdawc_attribute_input_name">                                 
    33         <input type="text" name="extra_product_fields[<?php echo esc_html( $index ); ?>][label]" value="<?php echo esc_attr( $field['label'] ); ?>" placeholder="<?php esc_html_e( 'Name of the label', 'extra-product-data-for-woocommerce' ); ?>" />
    34     </td>
    35     <td>
    36         <select id="exprdawc_attribute_type_<?php echo esc_html( $index ); ?>" name="extra_product_fields[<?php echo esc_html( $index ); ?>][type]" class="exprdawc_attribute_type">
    37             <option value="text" <?php selected( $field['type'], 'text' ); ?>><?php esc_html_e( 'Short Text', 'extra-product-data-for-woocommerce' ); ?></option>
    38             <option value="long_text" <?php selected( $field['type'], 'long_text' ); ?>><?php esc_html_e( 'Long Text', 'extra-product-data-for-woocommerce' ); ?></option>
    39             <option value="email" <?php selected( $field['type'], 'email' ); ?>><?php esc_html_e( 'Email', 'extra-product-data-for-woocommerce' ); ?></option>
    40             <option value="number" <?php selected( $field['type'], 'number' ); ?>><?php esc_html_e( 'Number', 'extra-product-data-for-woocommerce' ); ?></option>
    41             <option value="date" <?php selected( $field['type'], 'date' ); ?>><?php esc_html_e( 'Date', 'extra-product-data-for-woocommerce' ); ?></option>
    42             <option value="yes-no" <?php selected( $field['type'], 'yes-no' ); ?>><?php esc_html_e( 'Yes/No', 'extra-product-data-for-woocommerce' ); ?></option>
    43         </select>
    44     </td>
    45     <td class="exprdawc_attribute_require_checkbox">
    46         <input type="checkbox" class="checkbox" name="extra_product_fields[<?php echo esc_html( $index ); ?>][required]" value="1" <?php echo checked( 1, $field['required'], false ); ?> />
    47     </td>
    48     <td class="exprdawc_attribute_placeholder_text">
    49         <input type="text" name="extra_product_fields[<?php echo esc_html( $index ); ?>][placeholder_text]" value="<?php echo esc_attr( $field['placeholder_text'] ?? '' ); ?>" placeholder="<?php esc_html_e( 'Placeholder Text', 'extra-product-data-for-woocommerce' ); ?>" />
    50     </td>
    51     <td class="exprdawc_attribute_help_text">
    52         <input type="text" name="extra_product_fields[<?php echo esc_html( $index ); ?>][help_text]" value="<?php echo esc_attr( $field['help_text'] ); ?>" placeholder="<?php esc_html_e( 'Help Text', 'extra-product-data-for-woocommerce' ); ?>" />
    53     </td>
    54     <td>
    55         <button type="button" class="exprdawc_remove_custom_field button"><?php esc_html_e( 'Remove', 'extra-product-data-for-woocommerce' ); ?></button>
    56     </td>
    57 </tr>
     30<table class="exprdawc_fields_table" data-index="<?php echo esc_html( $index ); ?>">
     31    <tbody>
     32        <tr class="exprdawc_attribute">
     33            <td class="move"><i class="dashicons dashicons-move"></i></td>
     34            <td class="cl-arr"><i class="dashicons dashicons-arrow-up toggle-options"></i></td>
     35            <td class="exprdawc_attribute_input_name">                                 
     36                <input type="text" class="exprdawc_input exprdawc_textinput exprdawc_label" name="extra_product_fields[<?php echo esc_html( $index ); ?>][label]" value="<?php echo esc_attr( $field['label'] ); ?>" placeholder="<?php esc_html_e( 'Name of the label', 'extra-product-data-for-woocommerce' ); ?>" />
     37            </td>
     38            <td>
     39                <select id="exprdawc_attribute_type_<?php echo esc_html( $index ); ?>" name="extra_product_fields[<?php echo esc_html( $index ); ?>][type]" class="exprdawc_input exprdawc_attribute_type">
     40                    <option value="text" <?php selected( $field['type'], 'text' ); ?>><?php esc_html_e( 'Short Text', 'extra-product-data-for-woocommerce' ); ?></option>
     41                    <option value="long_text" <?php selected( $field['type'], 'long_text' ); ?>><?php esc_html_e( 'Long Text', 'extra-product-data-for-woocommerce' ); ?></option>
     42                    <option value="email" <?php selected( $field['type'], 'email' ); ?>><?php esc_html_e( 'Email', 'extra-product-data-for-woocommerce' ); ?></option>
     43                    <option value="number" <?php selected( $field['type'], 'number' ); ?>><?php esc_html_e( 'Number', 'extra-product-data-for-woocommerce' ); ?></option>
     44                    <option value="date" <?php selected( $field['type'], 'date' ); ?>><?php esc_html_e( 'Date', 'extra-product-data-for-woocommerce' ); ?></option>
     45                    <option value="yes-no" <?php selected( $field['type'], 'yes-no' ); ?>><?php esc_html_e( 'Yes/No', 'extra-product-data-for-woocommerce' ); ?></option>
     46                    <option value="radio" <?php selected( $field['type'], 'radio' ); ?>><?php esc_html_e( 'Radio Button', 'extra-product-data-for-woocommerce' ); ?></option>
     47                    <option value="checkbox" <?php selected( $field['type'], 'checkbox' ); ?>><?php esc_html_e( 'Checkbox', 'extra-product-data-for-woocommerce' ); ?></option>
     48                    <option value="select" <?php selected( $field['type'], 'select' ); ?>><?php esc_html_e( 'Select', 'extra-product-data-for-woocommerce' ); ?></option>
     49                </select>
     50            </td>
     51            <td>
     52                <button type="button" class="button exprdawc_remove_custom_field"><i class="dashicons dashicons-trash"></i></button>
     53                <input type="hidden" class="exprdawc_attribute_index" name="extra_product_fields[<?php echo esc_html( $index ); ?>][index]" value="<?php echo esc_attr( $field['index'] ?? $index ); ?>"/>
     54            </td>
     55        </tr>
     56        <tr class="exprdawc_options" style="display: none;">
     57            <td colspan="5">
     58
     59                <!-- General Option/Settings -->
     60                <table class="exprdawc_settings_table exprdawc_general_table">
     61                    <tbody>
     62                        <tr>
     63                            <td class="exprdawc_attribute_require_checkbox">
     64                                <label class="exprdawc_label" for="exprdawc_text_required_<?php echo esc_html( $index ); ?>">
     65                                    <input type="checkbox" id="exprdawc_text_required_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_checkbox checkbox" name="extra_product_fields[<?php echo esc_html( $index ); ?>][required]" value="1" <?php echo checked( 1, $field['required'], false ); ?> />
     66                                    <?php esc_html_e( 'Require input', 'extra-product-data-for-woocommerce' ); ?>
     67                                </label>
     68                                <label class="exprdawc_label" for="exprdawc_text_autofocus_<?php echo esc_html( $index ); ?>">
     69                                    <input type="checkbox" id="exprdawc_text_autofocus_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_checkbox exprdawc_autocomplete_field checkbox" name="extra_product_fields[<?php echo esc_html( $index ); ?>][autofocus]" value="1" <?php echo checked( 1, $field['autofocus'] ?? 0, false ); ?> />
     70                                    <?php esc_html_e( 'Autofocus this field on product page', 'extra-product-data-for-woocommerce' ); ?>
     71                                </label>
     72                                <!-- Enable Conditional Logic and show table -->
     73                                <label class="exprdawc_label" for="exprdawc_text_conditional_logic_<?php echo esc_html( $index ); ?>">
     74                                    <input type="checkbox" id="exprdawc_text_conditional_logic_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_checkbox exprdawc_conditional_logic_field checkbox" name="extra_product_fields[<?php echo esc_html( $index ); ?>][conditional_logic]" value="1" <?php echo checked( 1, $field['conditional_logic'] ?? 0, false ); ?> />
     75                                    <?php esc_html_e( 'Enable conditional logic', 'extra-product-data-for-woocommerce' ); ?>
     76                                </label>
     77                            </td>
     78                            <td class="exprdawc_attribute_placeholder_text">
     79                                <label class="exprdawc_label" for="exprdawc_text_placeholder_text_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Placeholder Text', 'extra-product-data-for-woocommerce' ); ?></label>
     80                                <input type="text" id="exprdawc_text_placeholder_text_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_textinput exprdawc_placeholder" name="extra_product_fields[<?php echo esc_html( $index ); ?>][placeholder_text]" value="<?php echo esc_attr( $field['placeholder_text'] ?? '' ); ?>" placeholder="<?php esc_html_e( 'Placeholder Text', 'extra-product-data-for-woocommerce' ); ?>" <?php echo in_array( $field['type'], array( 'radio', 'checkbox', 'select' ) ) ? 'disabled' : ''; ?> />
     81                            </td>
     82                            <td class="exprdawc_attribute_help_text">
     83                                <label class="exprdawc_label" for="exprdawc_text_help_text_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Help Text', 'extra-product-data-for-woocommerce' ); ?></label>
     84                                <input type="text" id="exprdawc_text_help_text_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_textinput exprdawc_helptext" name="extra_product_fields[<?php echo esc_html( $index ); ?>][help_text]" value="<?php echo esc_attr( $field['help_text'] ); ?>" placeholder="<?php esc_html_e( 'Help Text', 'extra-product-data-for-woocommerce' ); ?>" />
     85                            </td>
     86                            <td>
     87                                <label class="exprdawc_label" for="exprdawc_autocomplete_function_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Autocomplete Function', 'extra-product-data-for-woocommerce' ); ?></label>
     88                                <select id="exprdawc_autocomplete_function_<?php echo esc_html( $index ); ?>" name="extra_product_fields[<?php echo esc_html( $index ); ?>][autocomplete]" class="exprdawc_input exprdawc_attribute_type">
     89                                    <option value="on" <?php selected( $field['autocomplete'], 'on' ); ?>><?php esc_html_e( 'On (default)', 'extra-product-data-for-woocommerce' ); ?></option>
     90                                    <option value="off" <?php selected( $field['autocomplete'], 'off' ); ?>><?php esc_html_e( 'Off', 'extra-product-data-for-woocommerce' ); ?></option>
     91                                    <option value="address-level1" <?php selected( $field['autocomplete'], 'address-level1' ); ?>><?php esc_html_e( 'Address Level 1', 'extra-product-data-for-woocommerce' ); ?></option>
     92                                    <option value="address-level2" <?php selected( $field['autocomplete'], 'address-level2' ); ?>><?php esc_html_e( 'Address Level 2', 'extra-product-data-for-woocommerce' ); ?></option>
     93                                    <option value="address-level3" <?php selected( $field['autocomplete'], 'address-level3' ); ?>><?php esc_html_e( 'Address Level 3', 'extra-product-data-for-woocommerce' ); ?></option>
     94                                    <option value="address-level4" <?php selected( $field['autocomplete'], 'address-level4' ); ?>><?php esc_html_e( 'Address Level 4', 'extra-product-data-for-woocommerce' ); ?></option>
     95                                    <option value="address-line1" <?php selected( $field['autocomplete'], 'address-line1' ); ?>><?php esc_html_e( 'Address Line 1', 'extra-product-data-for-woocommerce' ); ?></option>
     96                                    <option value="address-line2" <?php selected( $field['autocomplete'], 'address-line2' ); ?>><?php esc_html_e( 'Address Line 2', 'extra-product-data-for-woocommerce' ); ?></option>
     97                                    <option value="address-line3" <?php selected( $field['autocomplete'], 'address-line3' ); ?>><?php esc_html_e( 'Address Line 3', 'extra-product-data-for-woocommerce' ); ?></option>
     98                                    <option value="bday" <?php selected( $field['autocomplete'], 'bday' ); ?>><?php esc_html_e( 'Birthday', 'extra-product-data-for-woocommerce' ); ?></option>
     99                                    <option value="bday-day" <?php selected( $field['autocomplete'], 'bday-day' ); ?>><?php esc_html_e( 'Birthday Day', 'extra-product-data-for-woocommerce' ); ?></option>
     100                                    <option value="bday-month" <?php selected( $field['autocomplete'], 'bday-month' ); ?>><?php esc_html_e( 'Birthday Month', 'extra-product-data-for-woocommerce' ); ?></option>
     101                                    <option value="bday-year" <?php selected( $field['autocomplete'], 'bday-year' ); ?>><?php esc_html_e( 'Birthday Year', 'extra-product-data-for-woocommerce' ); ?></option>
     102                                    <option value="cc-additional-name" <?php selected( $field['autocomplete'], 'cc-additional-name' ); ?>><?php esc_html_e( 'Credit Card Additional Name', 'extra-product-data-for-woocommerce' ); ?></option>
     103                                    <option value="cc-csc" <?php selected( $field['autocomplete'], 'cc-csc' ); ?>><?php esc_html_e( 'Credit Card CSC', 'extra-product-data-for-woocommerce' ); ?></option>
     104                                    <option value="cc-exp" <?php selected( $field['autocomplete'], 'cc-exp' ); ?>><?php esc_html_e( 'Credit Card Expiry', 'extra-product-data-for-woocommerce' ); ?></option>
     105                                    <option value="cc-exp-month" <?php selected( $field['autocomplete'], 'cc-exp-month' ); ?>><?php esc_html_e( 'Credit Card Expiry Month', 'extra-product-data-for-woocommerce' ); ?></option>
     106                                    <option value="cc-exp-year" <?php selected( $field['autocomplete'], 'cc-exp-year' ); ?>><?php esc_html_e( 'Credit Card Expiry Year', 'extra-product-data-for-woocommerce' ); ?></option>
     107                                    <option value="cc-family-name" <?php selected( $field['autocomplete'], 'cc-family-name' ); ?>><?php esc_html_e( 'Credit Card Family Name', 'extra-product-data-for-woocommerce' ); ?></option>
     108                                    <option value="cc-given-name" <?php selected( $field['autocomplete'], 'cc-given-name' ); ?>><?php esc_html_e( 'Credit Card Given Name', 'extra-product-data-for-woocommerce' ); ?></option>
     109                                    <option value="cc-name" <?php selected( $field['autocomplete'], 'cc-name' ); ?>><?php esc_html_e( 'Credit Card Name', 'extra-product-data-for-woocommerce' ); ?></option>
     110                                    <option value="cc-number" <?php selected( $field['autocomplete'], 'cc-number' ); ?>><?php esc_html_e( 'Credit Card Number', 'extra-product-data-for-woocommerce' ); ?></option>
     111                                    <option value="cc-type" <?php selected( $field['autocomplete'], 'cc-type' ); ?>><?php esc_html_e( 'Credit Card Type', 'extra-product-data-for-woocommerce' ); ?></option>
     112                                    <option value="country" <?php selected( $field['autocomplete'], 'country' ); ?>><?php esc_html_e( 'Country', 'extra-product-data-for-woocommerce' ); ?></option>
     113                                    <option value="country-name" <?php selected( $field['autocomplete'], 'country-name' ); ?>><?php esc_html_e( 'Country Name', 'extra-product-data-for-woocommerce' ); ?></option>
     114                                    <option value="email" <?php selected( $field['autocomplete'], 'email' ); ?>><?php esc_html_e( 'Email', 'extra-product-data-for-woocommerce' ); ?></option>
     115                                    <option value="language" <?php selected( $field['autocomplete'], 'language' ); ?>><?php esc_html_e( 'Language', 'extra-product-data-for-woocommerce' ); ?></option>
     116                                    <option value="photo" <?php selected( $field['autocomplete'], 'photo' ); ?>><?php esc_html_e( 'Photo', 'extra-product-data-for-woocommerce' ); ?></option>
     117                                    <option value="postal-code" <?php selected( $field['autocomplete'], 'postal-code' ); ?>><?php esc_html_e( 'Postal Code', 'extra-product-data-for-woocommerce' ); ?></option>
     118                                    <option value="sex" <?php selected( $field['autocomplete'], 'sex' ); ?>><?php esc_html_e( 'Sex', 'extra-product-data-for-woocommerce' ); ?></option>
     119                                    <option value="street-address" <?php selected( $field['autocomplete'], 'street-address' ); ?>><?php esc_html_e( 'Street Address', 'extra-product-data-for-woocommerce' ); ?></option>
     120                                    <option value="tel" <?php selected( $field['autocomplete'], 'tel' ); ?>><?php esc_html_e( 'Telephone', 'extra-product-data-for-woocommerce' ); ?></option>
     121                                    <option value="tel-area-code" <?php selected( $field['autocomplete'], 'tel-area-code' ); ?>><?php esc_html_e( 'Telephone Area Code', 'extra-product-data-for-woocommerce' ); ?></option>
     122                                    <option value="tel-country-code" <?php selected( $field['autocomplete'], 'tel-country-code' ); ?>><?php esc_html_e( 'Telephone Country Code', 'extra-product-data-for-woocommerce' ); ?></option>
     123                                    <option value="tel-extension" <?php selected( $field['autocomplete'], 'tel-extension' ); ?>><?php esc_html_e( 'Telephone Extension', 'extra-product-data-for-woocommerce' ); ?></option>
     124                                    <option value="tel-local" <?php selected( $field['autocomplete'], 'tel-local' ); ?>><?php esc_html_e( 'Telephone Local', 'extra-product-data-for-woocommerce' ); ?></option>
     125                                    <option value="tel-local-prefix" <?php selected( $field['autocomplete'], 'tel-local-prefix' ); ?>><?php esc_html_e( 'Telephone Local Prefix', 'extra-product-data-for-woocommerce' ); ?></option>
     126                                    <option value="tel-local-suffix" <?php selected( $field['autocomplete'], 'tel-local-suffix' ); ?>><?php esc_html_e( 'Telephone Local Suffix', 'extra-product-data-for-woocommerce' ); ?></option>
     127                                    <option value="tel-national" <?php selected( $field['autocomplete'], 'tel-national' ); ?>><?php esc_html_e( 'Telephone National', 'extra-product-data-for-woocommerce' ); ?></option>
     128                                    <option value="transaction-amount" <?php selected( $field['autocomplete'], 'transaction-amount' ); ?>><?php esc_html_e( 'Transaction Amount', 'extra-product-data-for-woocommerce' ); ?></option>
     129                                    <option value="transaction-currency" <?php selected( $field['autocomplete'], 'transaction-currency' ); ?>><?php esc_html_e( 'Transaction Currency', 'extra-product-data-for-woocommerce' ); ?></option>
     130                                    <option value="url" <?php selected( $field['autocomplete'], 'url' ); ?>><?php esc_html_e( 'URL', 'extra-product-data-for-woocommerce' ); ?></option>
     131                                </select>
     132                            </td>
     133                        </tr>
     134                    </tbody>
     135                </table>
     136                <hr>
     137
     138                <!-- Conditional Logic -->
     139                <table class="exprdawc_settings_table exprdawc_conditional_logic_table" style="display:<?php echo ( $field['conditional_logic'] ?? false ) ? 'table' : 'none'; ?>">
     140                    <tbody>
     141                        <tr>
     142                            <td colspan="3">
     143                                <label class="exprdawc_label"><?php esc_html_e( 'Conditionals', 'extra-product-data-for-woocommerce' ); ?></label>
     144                                <p><?php esc_html_e( 'Only show this field when conditional rules are true.', 'extra-product-data-for-woocommerce' ); ?></p>
     145                                <div class="exprdawc_conditional_rules">
     146                                    <?php if ( ! empty( $field['conditional_rules'] ) ) : ?>
     147                                        <?php foreach ( $field['conditional_rules'] as $rule_group_index => $rule_group ) : ?>
     148                                            <div class="exprdawc_rule_group_container">
     149                                                <div class="exprdawc_rule_group">
     150                                                    <?php foreach ( $rule_group as $rule_index => $rule ) : ?>
     151                                                        <div class="exprdawc_rule">
     152                                                            <select name="extra_product_fields[<?php echo esc_html( $index ); ?>][conditional_rules][<?php echo esc_html( $rule_group_index ); ?>][<?php echo esc_html( $rule_index ); ?>][field]" class="exprdawc_input exprdawc_conditional_field">
     153                                                                <option value=""><?php esc_html_e( 'Select Field', 'extra-product-data-for-woocommerce' ); ?></option>
     154                                                                <?php foreach ( $all_fields as $field_key => $field_label ) : ?>
     155                                                                    <option value="<?php echo esc_attr( $field_key ); ?>" <?php selected( $rule['field'], $field_key ); ?>><?php echo esc_html( $field_label ); ?></option>
     156                                                                <?php endforeach; ?>
     157                                                            </select>
     158                                                            <select name="extra_product_fields[<?php echo esc_html( $index ); ?>][conditional_rules][<?php echo esc_html( $rule_group_index ); ?>][<?php echo esc_html( $rule_index ); ?>][operator]" class="exprdawc_input exprdawc_conditional_operator">
     159                                                                <option value="field_is_empty" <?php selected( $rule['operator'], 'field_is_empty' ); ?>><?php esc_html_e( 'Field is empty', 'extra-product-data-for-woocommerce' ); ?></option>
     160                                                                <option value="field_is_not_empty" <?php selected( $rule['operator'], 'field_is_not_empty' ); ?>><?php esc_html_e( 'Field is not empty', 'extra-product-data-for-woocommerce' ); ?></option>       
     161                                                                <option value="equals" <?php selected( $rule['operator'], 'equals' ); ?>><?php esc_html_e( 'Equals', 'extra-product-data-for-woocommerce' ); ?></option>
     162                                                                <option value="not_equals" <?php selected( $rule['operator'], 'not_equals' ); ?>><?php esc_html_e( 'Not Equals', 'extra-product-data-for-woocommerce' ); ?></option>
     163                                                                <option value="greater_than" <?php selected( $rule['operator'], 'greater_than' ); ?>><?php esc_html_e( 'Greater Than', 'extra-product-data-for-woocommerce' ); ?></option>
     164                                                                <option value="less_than" <?php selected( $rule['operator'], 'less_than' ); ?>><?php esc_html_e( 'Less Than', 'extra-product-data-for-woocommerce' ); ?></option>
     165                                                            </select>
     166                                                            <input type="text" name="extra_product_fields[<?php echo esc_html( $index ); ?>][conditional_rules][<?php echo esc_html( $rule_group_index ); ?>][<?php echo esc_html( $rule_index ); ?>][value]" class="exprdawc_input exprdawc_conditional_value" value="<?php echo esc_attr( $rule['value'] ?? '' ); ?>" placeholder="<?php esc_html_e( 'Enter value', 'extra-product-data-for-woocommerce' ); ?>" />
     167                                                            <button type="button" class="button remove_rule"><i class="dashicons dashicons-trash"></i></button>
     168                                                            <button type="button" class="button add_rule">+ <?php esc_html_e( 'AND', 'extra-product-data-for-woocommerce' ); ?></button>
     169                                                        </div>
     170                                                    <?php endforeach; ?>
     171                                                    </div>
     172                                                </div>
     173                                               
     174                                                <?php if ( $rule_group_index < count( $field['conditional_rules'] ) - 1 ) : ?>
     175                                                    <h2><?php esc_html_e( 'Or', 'extra-product-data-for-woocommerce' ); ?></h2>
     176                                                <?php endif; ?>
     177                                            </div>
     178                                        <?php endforeach; ?>
     179                                    <?php else : ?>
     180                                        <div class="exprdawc_rule_group_container">
     181                                            <div class="exprdawc_rule_group">
     182                                                <div class="exprdawc_rule">
     183                                                    <select name="extra_product_fields[<?php echo esc_html( $index ); ?>][conditional_rules][0][0][field]" class="exprdawc_input exprdawc_conditional_field">
     184                                                        <option value=""><?php esc_html_e( 'None', 'extra-product-data-for-woocommerce' ); ?></option>
     185                                                        <?php foreach ( $all_fields as $field_key => $field_label ) : ?>
     186                                                            <option value="<?php echo esc_attr( $field_key ); ?>"><?php echo esc_html( $field_label ); ?></option>
     187                                                        <?php endforeach; ?>
     188                                                    </select>
     189                                                    <select name="extra_product_fields[<?php echo esc_html( $index ); ?>][conditional_rules][0][0][operator]" class="exprdawc_input exprdawc_conditional_operator">
     190                                                        <option value="field_is_empty"><?php esc_html_e( 'Field is empty', 'extra-product-data-for-woocommerce' ); ?></option>
     191                                                        <option value="field_is_not_empty"><?php esc_html_e( 'Field is not empty', 'extra-product-data-for-woocommerce' ); ?></option> 
     192                                                        <option value="equals"><?php esc_html_e( 'Equals', 'extra-product-data-for-woocommerce' ); ?></option>
     193                                                        <option value="not_equals"><?php esc_html_e( 'Not Equals', 'extra-product-data-for-woocommerce' ); ?></option>
     194                                                        <option value="greater_than"><?php esc_html_e( 'Greater Than', 'extra-product-data-for-woocommerce' ); ?></option>
     195                                                        <option value="less_than"><?php esc_html_e( 'Less Than', 'extra-product-data-for-woocommerce' ); ?></option>
     196                                                    </select>
     197                                                    <input type="text" name="extra_product_fields[<?php echo esc_html( $index ); ?>][conditional_rules][0][0][value]" class="exprdawc_input exprdawc_conditional_value" placeholder="<?php esc_html_e( 'Enter value', 'extra-product-data-for-woocommerce' ); ?>" />
     198                                                    <button type="button" class="button remove_rule"><i class="dashicons dashicons-trash"></i></button>
     199                                                    <button type="button" class="button add_rule">+ <?php esc_html_e( 'AND', 'extra-product-data-for-woocommerce' ); ?></button>
     200                                                </div>
     201                                            </div>
     202                                        </div>
     203                                    <?php endif; ?>
     204                                </div>
     205                                <button type="button" class="button add_rule_group">+ <?php esc_html_e( 'Add new rule group', 'extra-product-data-for-woocommerce' ); ?></button>
     206                            </td>
     207                        </tr>
     208                    </tbody>
     209                </table>
     210
     211                <!-- Text Area Option/Settings -->
     212                <table class="exprdawc_settings_table exprdawc_long_text_table" style="display:<?php echo 'long_text' === $field['type'] ? 'table' : 'none'; ?>">
     213                    <tbody>
     214                        <tr>
     215                            <td>
     216                                <label class="exprdawc_label" for="exprdawc_long_text_rows_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Rows', 'extra-product-data-for-woocommerce' ); ?></label>
     217                                <input type="number" id="exprdawc_long_text_rows_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_long_text_rows" name="extra_product_fields[<?php echo esc_html( $index ); ?>][rows]" value="<?php echo esc_attr( $field['rows'] ?? '2' ); ?>" />
     218                            </td>
     219                            <td>
     220                                <label class="exprdawc_label" for="exprdawc_long_text_cols_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Columns', 'extra-product-data-for-woocommerce' ); ?></label>
     221                                <input type="number" id="exprdawc_long_text_cols_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_long_text_cols" name="extra_product_fields[<?php echo esc_html( $index ); ?>][cols]" value="<?php echo esc_attr( $field['cols'] ?? '5' ); ?>" />
     222                            </td>
     223                            <td>
     224                                <label class="exprdawc_label" for="exprdawc_long_text_default_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Default Value', 'extra-product-data-for-woocommerce' ); ?></label>
     225                                <textarea id="exprdawc_long_text_default_<?php echo esc_html( $index ); ?>" class="exprdawc_textarea" rows="3" cols="30" placeholder="<?php esc_html_e( 'Enter a default text', 'extra-product-data-for-woocommerce' ); ?>" class="exprdawc_input exprdawc_long_text_cols" name="extra_product_fields[<?php echo esc_html( $index ); ?>][default]" value="<?php echo esc_attr( $field['default'] ?? '' ); ?>" ></textarea>
     226                            </td>
     227                        </tr>
     228                    </tbody>
     229                </table>
     230
     231                <!-- Text Option/Settings -->
     232                <table class="exprdawc_settings_table exprdawc_text_table" style="display:<?php echo 'text' === $field['type'] ? 'table' : 'none'; ?>">
     233                    <tbody>
     234                        <tr>
     235                            <td>
     236                                <label class="exprdawc_label" for="exprdawc_text_min_length_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Min length', 'extra-product-data-for-woocommerce' ); ?></label>
     237                                <input type="number" id="exprdawc_text_min_length_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_text_min_length" name="extra_product_fields[<?php echo esc_html( $index ); ?>][minlength]" value="<?php echo esc_attr( $field['minlength'] ?? '0' ); ?>" />
     238                            </td>
     239                            <td>
     240                                <label class="exprdawc_label" for="exprdawc_text_max_length_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Max length', 'extra-product-data-for-woocommerce' ); ?></label>
     241                                <input type="number" id="exprdawc_text_max_length_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_text_max_length" name="extra_product_fields[<?php echo esc_html( $index ); ?>][maxlength]" value="<?php echo esc_attr( $field['maxlength'] ?? '255' ); ?>" />
     242                            </td>
     243                            <td>
     244                                <label class="exprdawc_label" for="exprdawc_text_default_<?php echo esc_html( $index ); ?>"><?php esc_html_e( 'Default Value', 'extra-product-data-for-woocommerce' ); ?></label>
     245                                <input type="text" id="exprdawc_text_default_<?php echo esc_html( $index ); ?>" class="exprdawc_input exprdawc_text_max_length" placeholder="<?php esc_html_e( 'Enter a default text', 'extra-product-data-for-woocommerce' ); ?>" name="extra_product_fields[<?php echo esc_html( $index ); ?>][default]" value="<?php echo esc_attr( $field['default'] ?? '' ); ?>" />
     246                            </td>
     247                        </tr>
     248                    </tbody>
     249                </table>
     250
     251                <!-- Checbox, Radio, Select Area Option/Settings -->
     252                <table class="exprdawc_options_table" style="display:<?php echo empty( $field['options'] ) ? 'none' : 'table'; ?>">
     253                    <thead>
     254                        <tr>
     255                            <th></th>
     256                            <th>
     257                                <?php esc_html_e( 'Option Label', 'extra-product-data-for-woocommerce' ); ?>
     258                                <span class="dashicons dashicons-editor-help" title="<?php esc_html_e( 'This is the label for the option.', 'extra-product-data-for-woocommerce' ); ?>"></span>
     259                            </th>
     260                            <th>
     261                                <?php esc_html_e( 'Option Value', 'extra-product-data-for-woocommerce' ); ?>
     262                                <span class="dashicons dashicons-editor-help" title="<?php esc_html_e( 'This is the value for the option.', 'extra-product-data-for-woocommerce' ); ?>"></span>
     263                            </th>
     264                            <th>
     265                                <?php esc_html_e( 'Default', 'extra-product-data-for-woocommerce' ); ?>
     266                                <span class="dashicons dashicons-editor-help" title="<?php esc_html_e( 'Set as default option.', 'extra-product-data-for-woocommerce' ); ?>"></span>
     267                            </th>
     268                            <th><?php esc_html_e( 'Action', 'extra-product-data-for-woocommerce' ); ?></th>
     269                        </tr>
     270                    </thead>
     271                    <tbody>
     272                        <?php if ( ! empty( $field['options'] ) ) : ?>
     273                            <?php foreach ( $field['options'] as $option_index => $option ) : ?>
     274                                <?php if ( is_array( $option ) ) : ?>
     275                                    <tr>
     276                                        <td class="move"><i class="dashicons dashicons-move"></i></td>
     277                                        <td>
     278                                            <input type="text" class="exprdawc_input exprdawc_option_label" name="extra_product_fields[<?php echo esc_html( $index ); ?>][options][<?php echo esc_html( $option_index ); ?>][label]" value="<?php echo esc_attr( $option['label'] ); ?>" placeholder="<?php esc_html_e( 'Enter option label', 'extra-product-data-for-woocommerce' ); ?>" />
     279                                        </td>
     280                                        <td>
     281                                            <input type="text" class="exprdawc_input exprdawc_option_value" name="extra_product_fields[<?php echo esc_html( $index ); ?>][options][<?php echo esc_html( $option_index ); ?>][value]" value="<?php echo esc_attr( $option['value'] ); ?>" placeholder="<?php esc_html_e( 'Enter option value', 'extra-product-data-for-woocommerce' ); ?>" />
     282                                        </td>
     283                                        <td>
     284                                            <input type="radio" class="exprdawc_input exprdawc_radio exprdawc_option_default" name="extra_product_fields[<?php echo esc_html( $index ); ?>][default]" value="<?php echo esc_attr( $option['value'] ); ?>" <?php checked( isset( $field['default'] ) && $field['default'] === $option['value'] ); ?> />
     285                                        </td>
     286                                        <td>
     287                                            <button type="button" class="button remove_option"><i class="dashicons dashicons-trash"></i></button>
     288                                        </td>
     289                                    </tr>
     290                                <?php endif; ?>
     291                            <?php endforeach; ?>
     292                        <?php endif; ?>
     293                    </tbody>
     294                    <tfoot>
     295                        <tr>
     296                            <td colspan="4">
     297                                <button type="button" class="button add_option"><?php esc_html_e( 'Add Option', 'extra-product-data-for-woocommerce' ); ?></button>
     298                            </td>
     299                        </tr>
     300                    </tfoot>
     301                </table>
     302               
     303            </td>
     304        </tr>
     305    </tbody>
     306</table>
  • extra-product-data-for-woocommerce/trunk/src/templates/view/html-tab-extra-attributes.php

    r3198064 r3202511  
    55 * Copyright (c) 2024 IT-Dienstleistungen Drevermann - All Rights Reserved
    66 *
    7  * @package Triopsi licence manager
     7 * @package Extra Product Data for WooCommerce
    88 * @author Daniel Drevermann <info@triopsi.com>
    99 * @copyright Copyright (c) 2024, IT-Dienstleistungen Drevermann
     
    2828}
    2929?>
     30<input type="hidden" id="exprdawc_export_string" name="exprdawc_export_string" value="<?php echo $custom_fields ? wc_esc_json( json_encode( $custom_fields ) ) : ''; ?>" />
    3031<div id="extra-product-data" class="panel woocommerce_options_panel exprdawc_panel_wrapper">
    3132    <div class="toolbar toolbar-top">
    32         <div id="message" class="inline notice notice-info woocommerce-message">
    33             <p class="help">
    34                 <?php
    35                 esc_html_e(
    36                     'Add descriptive input fields to allow the customer to visualize your product in the product overview.',
    37                     'extra-product-data-for-woocommerce'
    38                 );
    39                 ?>
    40             </p>
    41         </div>
     33       
    4234    </div>
    4335    <div class="exprdawc_panel">
    4436        <h2><?php esc_html_e( 'Extra Attributes', 'extra-product-data-for-woocommerce' ); ?></h2>
     37        <p class="exprdawc_toolbar">
     38            <a href="#" class="exprdawc-import"><?php esc_html_e( 'Import', 'extra-product-data-for-woocommerce' ); ?></a>
     39            <a href="#" class="exprdawc-export"><?php esc_html_e( 'Export', 'extra-product-data-for-woocommerce' ); ?></a>
     40        </p>
    4541        <div class="exprdawc_attributes">
     42            <div class="exprdawc_no_entry_message">
     43                <p>
     44                    <?php esc_html_e( 'Add descriptive input fields to allow the customer to visualize your product in the product overview.', 'extra-product-data-for-woocommerce' ); ?>
     45                </p>
     46            </div>
    4647            <table class="field-options wp-list-table widefat exprdawc_field_table">
    47                 <thead>
     48                <thead id="exprdatawc_table_header">
    4849                    <tr>
    4950                        <th></th>
    50                         <th class="exprdawc_field_label"><?php esc_html_e( 'Label', 'extra-product-data-for-woocommerce' ); ?></th>
     51                        <th></th>
     52                        <th class="exprdawc_field_label"><?php esc_html_e( 'Title', 'extra-product-data-for-woocommerce' ); ?></th>
    5153                        <th class="exprdawc_field_type"><?php esc_html_e( 'Type', 'extra-product-data-for-woocommerce' ); ?></th>
    52                         <th class="exprdawc_field_required"><?php esc_html_e( 'Required', 'extra-product-data-for-woocommerce' ); ?></th>
    53                         <th class="exprdawc_field_placeholder"><?php esc_html_e( 'Placeholder', 'extra-product-data-for-woocommerce' ); ?></th>
    54                         <th class="exprdawc_field_help_text"><?php esc_html_e( 'Help Text', 'extra-product-data-for-woocommerce' ); ?></th>
    5554                        <th class="exprdawc_field_action"><?php esc_html_e( 'Action', 'extra-product-data-for-woocommerce' ); ?></th>
    5655                    </tr>
     
    5857                <tbody id="exprdawc_field_body">
    5958                <?php
    60                 $custom_fields = get_post_meta( get_the_ID(), '_extra_product_fields', true );
    6159                if ( ! empty( $custom_fields ) ) {
     60                    $all_fields = array();
     61                    // Loop through all fields and include the template.
    6262                    foreach ( $custom_fields as $index => $field ) {
     63                        $all_fields[$field['label']] = $field['label'];
     64                    }
     65                    foreach ( $custom_fields as $index => $field ) {
     66                        echo '<tr class="exprdawc_fields_wrapper">';
     67                        echo '<td colspan="5">';
    6368                        include EXPRDAWC_TEMPLATES . 'html-tab-extra-attributes-fields.php';
     69                        echo '</td>';
     70                        echo '</tr>';
    6471                    }
    6572                }
     
    6875                <tfoot>
    6976                    <tr>
    70                         <td colspan="8">
     77                        <td colspan="5">
    7178                            <button type="button" id="exprdawc_add_custom_field" class="button exprdawc_add_custom_field"><?php esc_html_e( 'Add Field', 'extra-product-data-for-woocommerce' ); ?></button>
    7279                        </td>
Note: See TracChangeset for help on using the changeset viewer.