Plugin Directory

Changeset 3161075


Ignore:
Timestamp:
10/01/2024 06:43:00 PM (18 months ago)
Author:
wpcommerz
Message:

1.2.1

  1. Improved: overall performance with faster result filtration.
  2. Improved: functions for conditional logic to hide multiple filters for a single card.
  3. Improved: functions for adding various conditions values for a single card attribute.
  4. Fixed: minor bugs.
Location:
guidant
Files:
135 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • guidant/trunk/assets/css/admin.css

    r3116503 r3161075  
    14981498
    14991499.guidant-main .guidant_form_group ul.select2-selection__rendered {
    1500     text-wrap: wrap !important;
    1501 }
     1500    text-wrap: wrap;
     1501}
  • guidant/trunk/assets/js/frontend.js

    r3132133 r3161075  
    171171
    172172jQuery(document).on("click", "[data-filter_to_show]", function () {
    173     if (typeof jQuery(this).data("filter_to_show") !== "undefined" && jQuery(this).data("filter_to_show") != null) {
    174       if (jQuery(this).data("filter_to_show") < 2) {
    175         jQuery(this)
    176           .closest(".guidantguide_filter")
    177           .find(".guidantguide_btn_next")
    178           .hide();
    179         jQuery(this)
    180           .closest(".guidantguide_filter")
    181           .find(".guidantguide_btn_submit")
    182           .show();
    183       } else {
    184         jQuery(this)
    185           .closest(".guidantguide_filter")
    186           .find(".guidantguide_btn_next")
    187           .show();
    188         jQuery(this)
    189           .closest(".guidantguide_filter")
    190           .find(".guidantguide_btn_submit")
    191           .hide();
    192       }
    193     }
     173
     174  if (jQuery(this).data("filter_to_show") == 1) {
     175    jQuery(this)
     176      .closest(".guidantguide_filter")
     177      .find(".guidantguide_btn_next")
     178      .hide();
     179    jQuery(this)
     180      .closest(".guidantguide_filter")
     181      .find(".guidantguide_btn_submit")
     182      .show();
     183  } else {
     184    jQuery(this)
     185      .closest(".guidantguide_filter")
     186      .find(".guidantguide_btn_next")
     187      .show();
     188    jQuery(this)
     189      .closest(".guidantguide_filter")
     190      .find(".guidantguide_btn_submit")
     191      .hide();
     192  }
    194193});
    195194
  • guidant/trunk/frontend/api/guidant_guide_submission.php

    r3128007 r3161075  
    11<?php
    22
    3 if (!class_exists('GuidantSubmissionHandler')) {
    4     require_once GUIDANT_PATH . 'frontend/api/guidant_guide_submission_handler.php';
     3/* Receive post data */
     4$resultant_post_id_element_wise = array();
     5if(isset($_REQUEST['security']) && isset($_REQUEST['guide_id']) && isset($_REQUEST['submissions'])) {
     6
     7    check_ajax_referer( 'guidant_hashkey', 'security' );
     8
     9    $guide_id = sanitize_text_field($_REQUEST['guide_id']);
     10    $submissions = $_REQUEST['submissions'];
     11    $submissions = urldecode($submissions);
     12    $submissions = stripcslashes($submissions);
     13    $submissions_obj = json_decode($submissions, TRUE);
     14
     15
     16
     17    $display_result = $this->settings->updateGuideSettings($guide_id, "display_result");
     18    $display_result = ($display_result == Null) ? "true" : $display_result;
     19
     20    $result_maximum = $this->settings->updateGuideSettings($guide_id, "result_maximum");
     21    $result_maximum = ($result_maximum == Null) ? "-1" : $result_maximum;
     22
     23    $submission_tracking = $this->settings->updateGuideSettings($guide_id, "submission_tracking");
     24    $submission_tracking = ($submission_tracking == Null) ? "enable" : $submission_tracking;
     25
     26    /* ========== Record Submission ========== */
     27    if($submission_tracking == "enable"){
     28        $submission_id = 0;
     29        if(is_array($submissions_obj)){
     30            if(sizeof($submissions_obj)>0){
     31                $user = wp_get_current_user();
     32                $user_id = ( isset( $user->ID ) ? (int) $user->ID : 0 );
     33                $submission_id = $this->settings->recordNewSubmission($guide_id, $user_id, current_time( 'timestamp' ));
     34                foreach ($submissions_obj as $filter_id=>$elements) {
     35                    foreach ($elements as $element) {
     36                        if($element['element_type'] == "card"){
     37                            $this->settings->insertSubmissionData($submission_id, $element['element_id'], ($element['element_value'] != 0) ? "checked" : "");
     38                        }else if($element['element_type'] == "slider"){
     39                            $this->settings->insertSubmissionData($submission_id, $element['element_id'], $element['element_value']);
     40                        }else if($element['element_type'] == "form"){
     41                            $this->settings->insertSubmissionData($submission_id, $element['element_id'], $element['element_value']);
     42                        }
     43                    }
     44                }
     45            }
     46        }
     47    }
     48
     49    /* ========== Record Submission ========== */
     50
     51
     52
     53
     54
     55
     56   
     57    foreach ($submissions_obj as $filter_id => $elements) {
     58        $filter_wise_resultant_ids = array();
     59        foreach ($elements as $element) {
     60            $element_wise_resultant_ids = array();
     61   
     62            if ($element['element_type'] == "card") {
     63                if ($element['element_value'] != 0) {
     64                    $condition_wise_resultant_ids = array();
     65                    $behavior = $this->settings->updateElementSettings($element['element_id'], "behavior");
     66                    $behavior = ($behavior == Null) ? "or" : $behavior;
     67   
     68                    $conditions = $this->settings->listAllConditions($element['element_id']);
     69                    foreach ($conditions as $single_condition) {
     70                        $attribute_type = $this->settings->updateConditionSettings($single_condition['condition_id'], "attribute_type");
     71                        $matching_type = $this->settings->updateConditionSettings($single_condition['condition_id'], "matching_type");
     72                        $value = $this->settings->updateConditionSettings($single_condition['condition_id'], "value");
     73   
     74                        // Decode the stored JSON value to get multiple values
     75                        $values = json_decode($value, true);
     76   
     77                        if (is_array($values)) {
     78                            foreach ($values as $single_value) {
     79                                if ($display_result == "true") {
     80                                    $condition_wise_resultant_ids[] = $this->renderer->queryBuilder($attribute_type, $matching_type, $single_value);
     81                                }
     82                            }
     83                        } else {
     84                            if ($display_result == "true") {
     85                                $condition_wise_resultant_ids[] = $this->renderer->queryBuilder($attribute_type, $matching_type, $value);
     86                            }
     87                        }
     88                    }
     89   
     90                    if ($behavior == "and") {
     91                        $condition_wise_resultant_ids = array_filter($condition_wise_resultant_ids); // filter out empty array
     92                        $element_wise_resultant_ids = array_merge($element_wise_resultant_ids, array_intersect(...$condition_wise_resultant_ids));
     93                    } else if ($behavior == "or") {
     94                        $element_wise_resultant_ids = array_merge($element_wise_resultant_ids, ...$condition_wise_resultant_ids);
     95                    }
     96                }
     97            } else if ($element['element_type'] == "slider") {
     98                $condition_wise_resultant_ids = array();
     99                $behavior = $this->settings->updateElementSettings($element['element_id'], "behavior");
     100                $behavior = ($behavior == Null) ? "or" : $behavior;
     101   
     102                $conditions = $this->settings->listAllConditions($element['element_id']);
     103                foreach ($conditions as $single_condition) {
     104                    $attribute_type = $this->settings->updateConditionSettings($single_condition['condition_id'], "attribute_type");
     105                    $matching_type = $this->settings->updateConditionSettings($single_condition['condition_id'], "matching_type");
     106                    $value = $element['element_value'];
     107   
     108                    if ($display_result == "true") {
     109                        $condition_wise_resultant_ids[] = $this->renderer->queryBuilder($attribute_type, $matching_type, $value);
     110                    }
     111                }
     112   
     113                if ($behavior == "and") {
     114                    $condition_wise_resultant_ids = array_filter($condition_wise_resultant_ids); // filter out empty array
     115                    $element_wise_resultant_ids = array_merge($element_wise_resultant_ids, array_intersect(...$condition_wise_resultant_ids));
     116                } else if ($behavior == "or") {
     117                    $element_wise_resultant_ids = array_merge($element_wise_resultant_ids, ...$condition_wise_resultant_ids);
     118                }
     119            } else if ($element['element_type'] == "form") {
     120                $this->settings->insertSubmissionData($submission_id, $element['element_id'], $element['element_value']);
     121            }
     122   
     123            $filter_wise_resultant_ids = array_merge($filter_wise_resultant_ids, $element_wise_resultant_ids);
     124        }
     125   
     126        if (sizeof($filter_wise_resultant_ids) > 0) {
     127            $resultant_post_id_element_wise[] = $filter_wise_resultant_ids;
     128        }
     129    }
     130
     131
     132    if($display_result == "true") {
     133
     134        if (sizeof($resultant_post_id_element_wise) > 1) {
     135            $filtered_post_ids = array_intersect(...$resultant_post_id_element_wise);
     136        } else {
     137            $filtered_post_ids = $resultant_post_id_element_wise[0];
     138        }
     139
     140        $filtered_post_ids = array_values($filtered_post_ids);
     141
     142
     143
     144
     145        /* Clear IDs not public/published post, pop the max ID into best result */
     146        $filtered_post_ids = $this->renderer->clearUnNecessaryIds($filtered_post_ids, $result_maximum);
     147        sort($filtered_post_ids);
     148        $best_result_id = array();
     149        $best_result_id[] = array_pop($filtered_post_ids);
     150        /* Clear IDs not public/published post, pop the max ID into best result */
     151
     152
     153
     154        $list_result_attributes = array();
     155        $list_results = $this->settings->listAllResults($guide_id);
     156        foreach ($list_results as $single_result) {
     157            $list_result_attributes[] = array(
     158                "attribute_type" => $this->settings->updateResultSettings($single_result['result_id'], "attribute_type"),
     159                "prefix" => $this->settings->updateResultSettings($single_result['result_id'], "prefix"),
     160                "button_text" => $this->settings->updateResultSettings($single_result['result_id'], "button_text"),
     161                "image_height" => $this->settings->updateResultSettings($single_result['result_id'], "image_height"),
     162            );
     163        }
     164
     165        $result = array("status" => 'true',
     166            "best_result" => $this->renderer->resultRender($best_result_id, $list_result_attributes),
     167            "other_results" => $this->renderer->resultRender($filtered_post_ids, $list_result_attributes)
     168        );
     169    }else{
     170        $result = array("status" => 'true');
     171    }
     172
     173
     174
     175}else{
     176    $result = array("status" => 'false');
    5177}
    6178
    7 $settings = new GuidantSettings();
    8 $utils = new GuidantUtils();
    9 $renderer = new GuidantRenderer();
    10179
    11 $processor = new GuidantSubmissionHandler($settings, $renderer, $utils);
    12 $processor->processRequest();
    13 
     180echo json_encode($result,  JSON_UNESCAPED_UNICODE);
  • guidant/trunk/frontend/class-guidant-ajax.php

    r3128007 r3161075  
    2828        }
    2929
     30
     31
    3032    }
    3133}
  • guidant/trunk/frontend/templates/views/single_card.php

    r3132133 r3161075  
    11<?php
    22
     3
    34$card_image = $this->settings->updateElementSettings($single_element['element_id'], "card_image");
    4 if (!empty($card_image)) {
    5     $card_image = "<img src=\"" . esc_url($card_image) . "\" width=\"100px\" height=\"100px\">";
     5if (isset($card_image)) {
     6    if (strlen(trim($card_image)) > 0) {
     7        $card_image = "<img src=\"" . $card_image . "\" width=\"100px\" height=\"100px\">";
     8    }
    69}
    710
     
    1013$total_filter_number = count($this->settings->listAllFilters($guide_id));
    1114
    12 $filter_to_show = array();
     15$filter_to_show = [];
    1316foreach ($list_logics as $single_logic) {
    1417    $selected_element = $this->settings->updateLogicSettings($single_logic['logic_id'], "selected_element");
     
    1619
    1720    if ($selected_element == $single_element['element_id']) {
     21        // Decode the JSON array and merge it with $filter_to_hide
    1822        $selected_filter_to_hide_array = json_decode($selected_filter_to_hide, true);
     23
     24        $number_of_filter_to_hide = count($selected_filter_to_hide_array);
     25        $filter_to_show[$single_element['element_id']] = $total_filter_number - $number_of_filter_to_hide;
     26
    1927        if (is_array($selected_filter_to_hide_array)) {
    20             $number_of_filter_to_hide = count($selected_filter_to_hide_array);
    21             $filter_to_show[$single_element['element_id']] = $total_filter_number - $number_of_filter_to_hide;
    2228            $filter_to_hide = array_merge($filter_to_hide, $selected_filter_to_hide_array);
    2329        }
     
    2935?>
    3036
    31 <div class="guidantguide_single_card guidantguide_element"
    32     data-element_id="<?php echo esc_attr($element_id) ?>"
    33     data-filter_to_hide="<?php echo esc_attr($filter_to_hide_arr_str) ?>"
    34     <?php if(isset($filter_to_show[$element_id])) { ?>
    35     data-filter_to_show="<?php echo esc_attr($filter_to_show[$element_id]) ?>">
    36     <?php } ?>
     37
     38<div class="guidantguide_single_card guidantguide_element" data-element_id="<?php echo esc_attr($single_element['element_id']) ?>" data-filter_to_hide="<?php echo esc_attr($filter_to_hide_arr_str) ?>" data-filter_to_show="<?php echo esc_attr($filter_to_show[$element_id] ?? '') ?>">
    3739    <?php echo isset($card_image) ? $card_image : ""; ?>
    38     <h4><?php echo esc_html($this->settings->updateElementSettings($element_id, "card_label")) ?></h4>
    39     <span
    40         class="<?php echo esc_attr($this->settings->updateFilterSettings($single_filter['filter_id'], "card_type")) ?>"></span>
     40    <h4><?php echo esc_attr($this->settings->updateElementSettings($single_element['element_id'], "card_label")) ?></h4>
     41    <span class="<?php echo esc_attr($this->settings->updateFilterSettings($single_filter['filter_id'], "card_type")) ?>"></span>
    4142</div>
  • guidant/trunk/guidant.php

    r3132133 r3161075  
    44 * Plugin URI:        https://wpcommerz.com/guidant/
    55 * Description:       Build Multi-step Guided Selling Process & Smart Forms to Convert 10X More Traffic Into Leads & New Customers.
    6  * Version:           1.2.0
     6 * Version:           1.2.1
    77 * Author:            WPCommerz
    88 * Author URI:        https://wpcommerz.com/
     
    1515
    1616// If this file is called directly, abort.
    17 if ( ! defined( 'WPINC' ) ) {
     17if (!defined('WPINC')) {
    1818    die;
    1919}
    2020
    21 define( 'GUIDANT_VERSION', '1.2.0' );
    22 defined( 'GUIDANT_PATH' ) or define( 'GUIDANT_PATH', plugin_dir_path( __FILE__ ) );
    23 defined( 'GUIDANT_URL' ) or define( 'GUIDANT_URL', plugin_dir_url( __FILE__ ) );
    24 defined( 'GUIDANT_BASE_PATH' ) or define( 'GUIDANT_BASE_PATH', plugin_basename(__FILE__) );
    25 defined( 'GUIDANT_IMG_DIR' ) or define( 'GUIDANT_IMG_DIR', plugin_dir_url( __FILE__ ) . 'assets/img/' );
    26 defined( 'GUIDANT_CSS_DIR' ) or define( 'GUIDANT_CSS_DIR', plugin_dir_url( __FILE__ ) . 'assets/css/' );
    27 defined( 'GUIDANT_JS_DIR' ) or define( 'GUIDANT_JS_DIR', plugin_dir_url( __FILE__ ) . 'assets/js/' );
     21define('GUIDANT_VERSION', '1.2.1');
     22defined('GUIDANT_PATH') or define('GUIDANT_PATH', plugin_dir_path(__FILE__));
     23defined('GUIDANT_URL') or define('GUIDANT_URL', plugin_dir_url(__FILE__));
     24defined('GUIDANT_BASE_PATH') or define('GUIDANT_BASE_PATH', plugin_basename(__FILE__));
     25defined('GUIDANT_IMG_DIR') or define('GUIDANT_IMG_DIR', plugin_dir_url(__FILE__) . 'assets/img/');
     26defined('GUIDANT_CSS_DIR') or define('GUIDANT_CSS_DIR', plugin_dir_url(__FILE__) . 'assets/css/');
     27defined('GUIDANT_JS_DIR') or define('GUIDANT_JS_DIR', plugin_dir_url(__FILE__) . 'assets/js/');
    2828
    2929/**
     
    3232 * @return void
    3333 */
    34 function appsero_init_tracker_guidant() {
     34function appsero_init_tracker_guidant()
     35{
    3536
    36     if ( ! class_exists( 'Appsero\Client' ) ) {
     37    if (!class_exists('Appsero\Client')) {
    3738        require_once __DIR__ . '/appsero/src/Client.php';
    3839    }
    3940
    40     $client = new Appsero\Client( '5862c38b-086b-417e-b2bd-6aeed31716a1', 'WP Guidant', __FILE__ );
     41    $client = new Appsero\Client('5862c38b-086b-417e-b2bd-6aeed31716a1', 'WP Guidant', __FILE__);
    4142
    4243    // Active insights
  • guidant/trunk/includes/GuidantRenderer.php

    r3128007 r3161075  
    6363                    $sql .= "INNER JOIN {$wpdb->terms} AS t ON (tt.term_id = t.term_id) ";
    6464                    break;
    65                 case "post_author":
    66                     $sql .= "INNER JOIN {$wpdb->users} AS u ON (p.post_author = u.ID) ";
    67                     break;
    6865            }
    6966
     
    7370                case "post_category":
    7471                    $sql .= "AND tt.taxonomy = 'category' ";
    75                     $sql .= "AND t.term_id {$matching_type_and_value} ";
     72                    $sql .= "AND t.name {$matching_type_and_value} ";
    7673                    break;
    7774                case "post_tags":
     
    8077                    break;
    8178                case "post_title":
    82                     $sql .= "AND p.ID {$matching_type_and_value} ";
     79                    $sql .= "AND p.post_title {$matching_type_and_value} ";
    8380                    break;
    8481                case "post_type":
     
    9289                    break;
    9390                case "post_author":
    94                     $sql .= "AND u.ID {$matching_type_and_value} ";
     91                    $sql .= "INNER JOIN {$wpdb->users} AS u ON (p.post_author = u.ID) ";
     92                    $sql .= "AND u.display_name {$matching_type_and_value} ";
    9593                    break;
    9694                case "woocommerce_category":
    9795                    if (class_exists('WooCommerce')) {
    9896                        $sql .= "AND tt.taxonomy = 'product_cat' ";
    99                         $sql .= "AND t.term_id {$matching_type_and_value} ";
     97                        $sql .= "AND t.name {$matching_type_and_value} ";
    10098                    }
    10199                    break;
     
    109107                    if (class_exists('WooCommerce')) {
    110108                        $sql .= "AND p.post_type = 'product' ";
    111                         $sql .= "AND p.ID {$matching_type_and_value} ";
     109                        $sql .= "AND p.post_title {$matching_type_and_value} ";
    112110                    }
    113111                    break;
     
    157155            $sql .= "GROUP BY p.ID ";
    158156
     157            // Prepare values for wpdb::prepare
    159158            if ($matching_type === 'between' || $matching_type === 'not_between') {
    160159                $valueParts = explode(",", $value);
     
    168167        }
    169168
    170 
    171 
    172169        public function clearUnnecessaryIds($post_id_arr, $limit = -1)
    173170        {
    174171            global $wpdb;
    175 
    176             // Check if the post_id_arr is empty
    177             if (empty($post_id_arr)) {
    178                 return [];
    179             }
    180 
    181             // Safely escape the post IDs for inclusion in the query
    182             $post_id_str = implode("','", array_map('esc_sql', $post_id_arr));
    183             $limit_sql = $limit != -1 ? $wpdb->prepare("LIMIT %d", $limit) : "";
    184 
    185             // Construct the query
     172            $post_id_str = implode("','", $post_id_arr);
     173            $limit_sql = $limit != -1 ? $wpdb->prepare(" LIMIT %d", $limit) : "";
    186174            $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_status = 'publish' AND ID IN ('{$post_id_str}') ORDER BY ID DESC {$limit_sql}";
    187 
    188             // Execute the query and get the results
    189175            $listPosts = $wpdb->get_results($sql, ARRAY_A);
    190 
    191             // Return the list of IDs
    192176            return wp_list_pluck($listPosts, 'ID');
    193177        }
    194178
    195 
    196179        public function resultRender($post_id_arr, $list_result_attributes)
    197180        {
     181            global $wpdb;
     182            $post_id_str = implode("','", $post_id_arr);
     183
    198184            $output = '';
    199185
    200             foreach ($post_id_arr as $post_id) {
    201                 $post = get_post($post_id);
    202                 if (!$post) {
    203                     continue;
     186            $sql = "SELECT * FROM {$wpdb->prefix}posts WHERE post_status = 'publish'
     187                                    AND ID IN ('{$post_id_str}') ORDER BY ID DESC";
     188            $listPosts = $wpdb->get_results($sql);
     189            if (!empty($listPosts)) {
     190                foreach ($listPosts as $post) {
     191                    $output .= "<div class=\"single_post\">";
     192
     193                    foreach ($list_result_attributes as $single_result_attribute) {
     194                        $attribute_name = $single_result_attribute['attribute_type'];
     195                        $prefix = isset($single_result_attribute['prefix']) ? trim($single_result_attribute['prefix']) . " " : " ";
     196
     197                        // Default values for optional attributes
     198                        $button_text = isset($single_result_attribute['button_text']) ? $single_result_attribute['button_text'] : 'View';
     199                        $image_height = isset($single_result_attribute['image_height']) ? $single_result_attribute['image_height'] : '200';
     200                        $add_to_cart_btn_default_text = isset($single_result_attribute['add_to_cart_btn_default_text']) ? $single_result_attribute['add_to_cart_btn_default_text'] : 'Add to Cart';
     201                        $add_to_cart_btn_loading_text = isset($single_result_attribute['add_to_cart_btn_loading_text']) ? $single_result_attribute['add_to_cart_btn_loading_text'] : 'Adding...';
     202                        $add_to_cart_btn_added_text = isset($single_result_attribute['add_to_cart_btn_added_text']) ? $single_result_attribute['add_to_cart_btn_added_text'] : 'Added to Cart';
     203
     204                        switch ($attribute_name) {
     205                            case 'post_category':
     206                                $post_categories = get_the_terms($post->ID, 'category');
     207                                if ($post_categories && !is_wp_error($post_categories)) {
     208                                    $post_categories_str = join(', ', wp_list_pluck($post_categories, 'name'));
     209                                    $output .= "<div class=\"post_category\">{$prefix}{$post_categories_str}</div>";
     210                                }
     211                                break;
     212                            case 'post_title':
     213                                $output .= "<div class=\"post_title\">{$prefix}{$post->post_title}</div>";
     214                                break;
     215                            case 'post_date':
     216                                $output .= "<div class=\"post_date\">{$prefix}{$post->post_date}</div>";
     217                                break;
     218                            case 'post_modified':
     219                                $output .= "<div class=\"post_modified\">{$prefix}{$post->post_modified}</div>";
     220                                break;
     221                            case 'post_author':
     222                                $author_name = get_the_author_meta('display_name', $post->post_author);
     223                                $output .= "<div class=\"post_author\">{$prefix}" . esc_html($author_name) . "</div>";
     224                                break;
     225                            case 'post_thumbnail':
     226                                if (has_post_thumbnail($post->ID)) {
     227                                    $image_url = get_the_post_thumbnail_url($post->ID, 'post-thumbnail');
     228                                    $output .= "<div class=\"post_thumbnail\"><img style='height: {$image_height}px !important;' src=\"{$image_url}\"></div>";
     229                                }
     230                                break;
     231                            case 'post_excerpt':
     232                                $excerpt = get_the_excerpt($post);
     233                                $output .= "<div class=\"post_excerpt\">{$prefix}" . esc_html($excerpt) . "</div>";
     234                                break;
     235                            case 'post_permalink':
     236                                $permalink = get_permalink($post);
     237                                $output .= "<div class=\"post_permalink\"><a target='_blank' href=\"{$permalink}\">{$button_text}</a></div>";
     238                                break;
     239                            case 'woocommerce_category':
     240                                if (class_exists('WooCommerce')) {
     241                                    $terms = wp_get_post_terms($post->ID, 'product_cat');
     242                                    if (!empty($terms)) {
     243                                        $category_names = wp_list_pluck($terms, 'name');
     244                                        $output .= "<div class=\"woocommerce_category\">{$prefix}" . implode(', ', $category_names) . "</div>";
     245                                    }
     246                                }
     247                                break;
     248                            case 'woocommerce_price':
     249                                if (class_exists('WooCommerce')) {
     250                                    $price = get_post_meta($post->ID, '_price', true);
     251                                    if (!empty($price)) {
     252                                        $output .= "<div class=\"woocommerce_price\">{$prefix}" . wc_price($price) . "</div>";
     253                                    }
     254                                }
     255                                break;
     256                            case 'woocommerce_add_to_cart':
     257                                if (class_exists('WooCommerce')) {
     258                                    $product = wc_get_product($post->ID);
     259                                    if ($product && $product->is_type('simple')) {
     260                                        $product_id = $product->get_id();
     261                                        $product_sku = $product->get_sku();
     262                                        $add_to_cart_url = $product->add_to_cart_url();
     263                                        $output .= "<div class=\"woocommerce_add_to_cart\" data-add_to_cart_btn_default_text=\"{$add_to_cart_btn_default_text}\" data-add_to_cart_btn_loading_text=\"{$add_to_cart_btn_loading_text}\" data-add_to_cart_btn_added_text=\"{$add_to_cart_btn_added_text}\"><a href=\"{$add_to_cart_url}\" data-product_id=\"{$product_id}\" data-product_sku=\"{$product_sku}\" class=\"ajax_add_to_cart add_to_cart_button\">{$add_to_cart_btn_default_text}</a></div>";
     264                                    }
     265                                }
     266                                break;
     267                            case 'custom_meta':
     268                                if (strpos($attribute_name, 'post_meta_') !== false) {
     269                                    $meta_key = str_replace("post_meta_", "", $attribute_name);
     270                                    $post_meta = get_post_meta($post->ID, $meta_key, true);
     271                                    $output .= "<div class=\"custom_meta\">{$prefix}" . esc_html($post_meta) . "</div>";
     272                                }
     273                                break;
     274                            default:
     275                                // Handle other attributes similarly
     276                                break;
     277                        }
     278                    }
     279
     280                    $output .= "</div>";
    204281                }
    205 
    206                 $output .= "<div class=\"single_post\">";
    207 
    208                 foreach ($list_result_attributes as $single_result_attribute) {
    209                     $attribute_name = $single_result_attribute['attribute_type'];
    210                     $prefix = isset($single_result_attribute['prefix']) ? trim($single_result_attribute['prefix']) . " " : " ";
    211 
    212                     // Default values for optional attributes
    213                     $button_text = isset($single_result_attribute['button_text']) ? $single_result_attribute['button_text'] : 'View';
    214                     $image_height = isset($single_result_attribute['image_height']) ? $single_result_attribute['image_height'] : '200';
    215                     $add_to_cart_btn_default_text = isset($single_result_attribute['add_to_cart_btn_default_text']) ? $single_result_attribute['add_to_cart_btn_default_text'] : 'Add to Cart';
    216                     $add_to_cart_btn_loading_text = isset($single_result_attribute['add_to_cart_btn_loading_text']) ? $single_result_attribute['add_to_cart_btn_loading_text'] : 'Adding...';
    217                     $add_to_cart_btn_added_text = isset($single_result_attribute['add_to_cart_btn_added_text']) ? $single_result_attribute['add_to_cart_btn_added_text'] : 'Added to Cart';
    218 
    219                     switch ($attribute_name) {
    220                         case 'post_category':
    221                             $post_categories = get_the_terms($post->ID, 'category');
    222                             if ($post_categories && !is_wp_error($post_categories)) {
    223                                 $post_categories_str = join(', ', wp_list_pluck($post_categories, 'name'));
    224                                 $output .= "<div class=\"post_category\">{$prefix}{$post_categories_str}</div>";
    225                             }
    226                             break;
    227                         case 'post_title':
    228                             $output .= "<div class=\"post_title\">{$prefix}{$post->post_title}</div>";
    229                             break;
    230                         case 'post_date':
    231                             $output .= "<div class=\"post_date\">{$prefix}{$post->post_date}</div>";
    232                             break;
    233                         case 'post_modified':
    234                             $output .= "<div class=\"post_modified\">{$prefix}{$post->post_modified}</div>";
    235                             break;
    236                         case 'post_author':
    237                             $author_name = get_the_author_meta('display_name', $post->post_author);
    238                             $output .= "<div class=\"post_author\">{$prefix}" . esc_html($author_name) . "</div>";
    239                             break;
    240                         case 'post_thumbnail':
    241                             if (has_post_thumbnail($post->ID)) {
    242                                 $image_url = get_the_post_thumbnail_url($post->ID, 'post-thumbnail');
    243                                 $output .= "<div class=\"post_thumbnail\"><img style='height: {$image_height}px !important;' src=\"{$image_url}\"></div>";
    244                             }
    245                             break;
    246                         case 'post_excerpt':
    247                             $excerpt = get_the_excerpt($post);
    248                             $output .= "<div class=\"post_excerpt\">{$prefix}" . esc_html($excerpt) . "</div>";
    249                             break;
    250                         case 'post_permalink':
    251                             $permalink = get_permalink($post);
    252                             $output .= "<div class=\"post_permalink\"><a target='_blank' href=\"{$permalink}\">{$button_text}</a></div>";
    253                             break;
    254                         case 'woocommerce_category':
    255                             if (class_exists('WooCommerce')) {
    256                                 $terms = wp_get_post_terms($post->ID, 'product_cat');
    257                                 if (!empty($terms)) {
    258                                     $category_names = wp_list_pluck($terms, 'name');
    259                                     $output .= "<div class=\"woocommerce_category\">{$prefix}" . implode(', ', $category_names) . "</div>";
    260                                 }
    261                             }
    262                             break;
    263                         case 'woocommerce_price':
    264                             if (class_exists('WooCommerce')) {
    265                                 $price = get_post_meta($post->ID, '_price', true);
    266                                 if (!empty($price)) {
    267                                     $output .= "<div class=\"woocommerce_price\">{$prefix}" . wc_price($price) . "</div>";
    268                                 }
    269                             }
    270                             break;
    271                         case 'woocommerce_add_to_cart':
    272                             if (class_exists('WooCommerce')) {
    273                                 $product = wc_get_product($post->ID);
    274                                 if ($product && $product->is_type('simple')) {
    275                                     $product_id = $product->get_id();
    276                                     $product_sku = $product->get_sku();
    277                                     $add_to_cart_url = $product->add_to_cart_url();
    278                                     $output .= "<div class=\"woocommerce_add_to_cart\" data-add_to_cart_btn_default_text=\"{$add_to_cart_btn_default_text}\" data-add_to_cart_btn_loading_text=\"{$add_to_cart_btn_loading_text}\" data-add_to_cart_btn_added_text=\"{$add_to_cart_btn_added_text}\"><a href=\"{$add_to_cart_url}\" data-product_id=\"{$product_id}\" data-product_sku=\"{$product_sku}\" class=\"ajax_add_to_cart add_to_cart_button\">{$add_to_cart_btn_default_text}</a></div>";
    279                                 }
    280                             }
    281                             break;
    282                         case 'custom_meta':
    283                             if (strpos($attribute_name, 'post_meta_') !== false) {
    284                                 $meta_key = str_replace("post_meta_", "", $attribute_name);
    285                                 $post_meta = get_post_meta($post->ID, $meta_key, true);
    286                                 $output .= "<div class=\"custom_meta\">{$prefix}" . esc_html($post_meta) . "</div>";
    287                             }
    288                             break;
    289                         default:
    290                             // Handle other attributes similarly
    291                             break;
    292                     }
    293                 }
    294 
    295                 $output .= "</div>";
    296             }
    297 
     282            }
    298283            return $output;
    299284        }
  • guidant/trunk/includes/GuidantSettings.php

    r3117743 r3161075  
    387387            $key = substr(str_shuffle(str_repeat($x = '123456789', ceil($length / strlen($x)))), 1, $length);
    388388            foreach ($dataSubmissions as $singleSubmission){
    389                 if(isset($singleSubmission['submission_id'])){
    390                     if($singleSubmission['submission_id'] == $key){
     389                if(isset($singleField['submission_id'])){
     390                    if($singleField['submission_id'] == $key){
    391391                        $exits = true;
    392392                    }
  • guidant/trunk/includes/GuidantUtils.php

    r3128007 r3161075  
    119119        public function getGuidantCustomFields($list_fields, $search)
    120120        {
    121             $wpguidantCustomFields = array();
     121            $guidantCustomFields = array();
    122122            foreach ($list_fields as $single_field) {
    123                 $wpguidantCustomFields[] = array("id" => "post_meta_" . $single_field['field_id'], "text" => "[Custom Field] " . $single_field['field_label']);
    124             }
    125             return $this->filterBySearch($wpguidantCustomFields, $search);
     123                $guidantCustomFields[] = array("id" => "post_meta_" . $single_field['field_id'], "text" => "[Custom Field] " . $single_field['field_label']);
     124            }
     125            return $this->filterBySearch($guidantCustomFields, $search);
    126126        }
    127127
     
    184184                    $terms = get_terms('category', $args);
    185185                    foreach ($terms as $term) {
    186                         $attributeValues[] = array("id" => $term->term_id, "text" => $term->name);
     186                        $attributeValues[] = array("id" => $term->name, "text" => $term->name);
    187187                    }
    188188                    break;
     
    198198                    $posts = get_posts($args);
    199199                    foreach ($posts as $post) {
    200                         $attributeValues[] = array("id" => $post->ID, "text" => $post->post_title);
     200                        $attributeValues[] = array("id" => $post->post_title, "text" => $post->post_title);
    201201                    }
    202202                    break;
     
    265265                    $users = get_users(array('search' => $search));
    266266                    foreach ($users as $user) {
    267                         $attributeValues[] = array("id" => $user->ID, "text" => $user->display_name);
     267                        $attributeValues[] = array("id" => $user->display_name, "text" => $user->display_name);
    268268                    }
    269269                    break;
     
    289289                        $terms = get_terms($args);
    290290                        foreach ($terms as $term) {
    291                             $attributeValues[] = array("id" => $term->term_id, "text" => $term->name);
     291                            $attributeValues[] = array("id" => $term->name, "text" => $term->name);
    292292                        }
    293293                    }
     
    313313                        $query = new WP_Query($args);
    314314                        if ($query->posts) {
    315                             $unique_tags = array();
    316315                            foreach ($query->posts as $post_id) {
    317316                                $tags = wp_get_post_terms($post_id, 'product_tag');
    318317                                foreach ($tags as $tag) {
    319                                     if (!in_array($tag->name, $unique_tags)) {
    320                                         $unique_tags[] = $tag->name;
    321                                         $attributeValues[] = array("id" => $tag->name, "text" => $tag->name);
    322                                     }
     318                                    $attributeValues[] = array("id" => $tag->name, "text" => $tag->name);
    323319                                }
    324320                            }
     
    340336                        $products = get_posts($args);
    341337                        foreach ($products as $product) {
    342                             $attributeValues[] = array("id" => $product->ID, "text" => $product->post_title);
     338                            $attributeValues[] = array("id" => $product->post_title, "text" => $product->post_title);
    343339                        }
    344340                    }
     
    519515                            foreach ($terms as $term) {
    520516                                $attributeValues[] = array("id" => $term->slug, "text" => $term->name);
     517                                file_put_contents('log.txt', print_r($attributeValues, true), FILE_APPEND);
    521518                            }
    522519                        }
     
    573570            return $attributeValues;
    574571        }
     572
     573
     574
     575
    575576
    576577        public function getIPAddress()
     
    586587            return $ip;
    587588        }
    588 
    589 
    590        
    591589    }
    592590}
  • guidant/trunk/readme.txt

    r3132133 r3161075  
    55Requires PHP: 7.4
    66Requires at least: 6.5
    7 Tested up to: 6.6.1
    8 Stable tag: 1.2.0
     7Tested up to: 6.6.2
     8Stable tag: 1.2.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    345345== Changelog ==
    346346
     347= 1.2.1 =
     3481. Improved: overall performance with faster result filtration.
     3492. Improved: functions for conditional logic to hide multiple filters for a single card.
     3503. Improved: functions for adding various conditions values for a single card attribute.
     3514. Fixed: minor bugs.
     352
    347353= 1.2.0 =
    3483541. Fixed: minor bugs.
    349355
    350 1.1.9
     356= 1.1.9 =
    3513571.Fixed JavaScript bugs.
    3523582.Fixed Issue with different language WooCommerce product not found.
Note: See TracChangeset for help on using the changeset viewer.