ch in SKU', 'ajax-search-for-woocommerce' ), 'type' => 'checkbox', 'desc' => dgoraAsfwFs()->is_premium() ? __( 'searching also in variable products SKU', 'ajax-search-for-woocommerce' ) : sprintf( __( 'Searching in variable products SKU is available only in the pro version.', 'ajax-search-for-woocommerce' ), Upgrade::getUpgradeUrl() ), 'default' => 'off', ), 200 => array( 'name' => 'search_in_product_attributes', 'label' => __( 'Search in attributes', 'ajax-search-for-woocommerce' ), 'class' => 'dgwt-wcas-premium-only', 'type' => 'checkbox', 'default' => 'off', ), 250 => array( 'name' => 'search_in_product_tax_product_cat', 'label' => __( 'Search in categories', 'ajax-search-for-woocommerce' ), 'class' => 'js-dgwt-wcas-adv-settings dgwt-wcas-premium-only', 'type' => 'checkbox', 'default' => 'off', ), 275 => array( 'name' => 'search_in_product_tax_product_tag', 'label' => __( 'Search in tags', 'ajax-search-for-woocommerce' ), 'class' => 'js-dgwt-wcas-adv-settings dgwt-wcas-premium-only', 'type' => 'checkbox', 'default' => 'off', ), 300 => array( 'name' => 'search_in_custom_fields', 'label' => __( 'Search in custom fields', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'search_in_custom_fields', __( 'Make your custom fields searchable from our search bar.', 'ajax-search-for-woocommerce' ) . ' ' . sprintf( $readMore, $customFieldsLink ) ), 'class' => 'dgwt-wcas-premium-only', 'type' => 'text', 'default' => '', ), 350 => array( 'name' => 'exclude_out_of_stock', 'label' => __( "Exclude “out of stock” products", 'ajax-search-for-woocommerce' ), 'type' => 'checkbox', 'default' => 'off', ), 400 => array( 'name' => 'search_scope_fuzziness_head', 'label' => __( 'Fuzziness', 'ajax-search-for-woocommerce' ), 'type' => 'head', 'class' => 'dgwt-wcas-sgs-header' ), 500 => array( 'name' => 'search_synonyms_head', 'label' => __( 'Synonyms', 'ajax-search-for-woocommerce' ), 'type' => 'head', 'class' => 'dgwt-wcas-sgs-header js-dgwt-wcas-adv-settings' ), 520 => array( 'name' => 'search_synonyms', 'label' => __( 'Synonyms', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'synonyms', sprintf( __( 'The synonyms feature allows your users to find more relevant results. If your products have alternative names and users often misspell them, consider adding synonyms. Read more about this feature.', 'ajax-search-for-woocommerce' ), $synonymsLink ) ), 'type' => 'textarea', 'desc' => __( 'Synonyms should be separated by a comma. Each new synonyms group is entered in a new line. You can use a phrase instead of a single word.

Sample list:

sofa, couch, davenport, divan, settee
big, grand, great, large, outsize
', 'ajax-search-for-woocommerce' ), 'class' => 'dgwt-wcas-settings-synonyms js-dgwt-wcas-adv-settings dgwt-wcas-premium-only' ), 600 => array( 'name' => 'filter_products_head', 'label' => __( 'Exclude/include products', 'ajax-search-for-woocommerce' ), 'type' => 'head', 'class' => 'dgwt-wcas-sgs-header js-dgwt-wcas-adv-settings' ), 625 => array( 'name' => 'filter_products_mode', 'label' => __( 'Filtering mode', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'filter_products_mode', __( 'Exclude the product group from the search results or allow search only among the indicated product group.', 'ajax-search-for-woocommerce' ) . ' ' . sprintf( $readMore, $excludeIncludeLink ), '', 'right' ), 'class' => 'js-dgwt-wcas-adv-settings dgwt-wcas-premium-only', 'type' => 'select', 'options' => array( 'exclude' => __( 'Exclude', 'ajax-search-for-woocommerce' ), 'include' => __( 'Include', 'ajax-search-for-woocommerce' ), ), 'default' => 'exclude', ), 650 => array( 'name' => 'filter_products_rules', 'label' => __( 'Filters', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'filter_products_head', __( 'Filters that specify the product group and taxonomy that will be affected by the above mode', 'ajax-search-for-woocommerce' ), '', 'right' ), 'type' => 'filters_rules_plug', 'class' => 'js-dgwt-wcas-adv-settings dgwt-wcas-premium-only', 'default' => '[]', ), ) ), 'dgwt_wcas_performance' => apply_filters( 'dgwt/wcas/settings/section=performance', array( 0 => array( 'name' => 'pro_features', 'label' => __( 'Pro features', 'ajax-search-for-woocommerce' ), 'type' => 'desc', 'desc' => Helpers::featuresHtml(), ), 10 => array( 'name' => 'search_engine_head', 'label' => __( 'Speed up search!', 'ajax-search-for-woocommerce' ), 'type' => 'head', 'class' => 'dgwt-wcas-sgs-header' ), 100 => array( 'name' => 'indexer_schedule_head', 'label' => __( 'Scheduling indexing', 'ajax-search-for-woocommerce' ), 'type' => 'head', 'class' => 'dgwt-wcas-sgs-header js-dgwt-wcas-adv-settings' ), 110 => array( 'name' => 'indexer_schedule', 'label' => __( 'Enable Scheduler', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'indexer-schedule', __( "In most cases, you don't need to use the scheduler because the search index updates when you edit products. If you use import tools or custom code to refresh prices or bulk add/edit products, the indexing scheduler will be helpful.", 'ajax-search-for-woocommerce' ) . ' ' . sprintf( $readMore, $schedulerLink ) ), 'type' => 'checkbox', 'size' => 'small', 'class' => 'dgwt-wcas-options-cb-toggle js-dgwt-wcas-cbtgroup-indexer-schedule js-dgwt-wcas-adv-settings dgwt-wcas-premium-only', 'default' => 'off', ), 120 => array( 'name' => 'indexer_schedule_interval', 'label' => __( 'Interval', 'ajax-search-for-woocommerce' ), 'type' => 'select', 'class' => 'js-dgwt-wcas-cbtgroup-indexer-schedule js-dgwt-wcas-adv-settings dgwt-wcas-premium-only', 'options' => array( 'daily' => __( 'daily', 'ajax-search-for-woocommerce' ), 'weekly' => __( 'weekly', 'ajax-search-for-woocommerce' ), ), 'default' => 'weekly', ), 130 => array( 'name' => 'indexer_schedule_start_time', 'label' => __( 'Schedule time', 'ajax-search-for-woocommerce' ), 'type' => 'select', 'class' => 'js-dgwt-wcas-cbtgroup-indexer-schedule js-dgwt-wcas-adv-settings dgwt-wcas-premium-only', 'options' => Helpers::getHours(), 'default' => 3, ), ) ) ); $fuzzinesText1 = '' . __( 'Increases sales conversions.', 'ajax-search-for-woocommerce' ) . ''; $fuzzinesText2 = sprintf( __( 'Returns suggestions based on likely relevance, even though a search keyword may not exactly match. E.g if you type “iphome” you get the same results as for “iphone”. Read more about the fuzzy search feature.', 'ajax-search-for-woocommerce' ), $fuzzySearchLink ); if ( dgoraAsfwFs()->is_premium() ) { if ( dgoraAsfwFs()->is__premium_only() ) { // Custom fields option $settingsFields['dgwt_wcas_search'][300] = array( 'name' => 'search_in_custom_fields', 'label' => __( 'Search in custom fields', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'search_in_custom_fields', __( 'Make your custom fields searchable from our search bar.', 'ajax-search-for-woocommerce' ) . ' ' . sprintf( $readMore, $customFieldsLink ) ), 'type' => 'selectize', 'options' => Helpers::isSettingsPage() ? Helpers::getSearchableCustomFields() : array(), 'sanitize_callback' => array( '\DgoraWcas\Admin\SettingsAPI', 'sanitize_selectize_custom_fields__premium_only' ), 'desc' => __( 'select the custom fields you want to add to the search scope', 'ajax-search-for-woocommerce' ), ); // Fuzzy search option $settingsFields['dgwt_wcas_search'][450] = array( 'name' => 'fuzziness_enabled', 'label' => __( 'Fuzzy matching', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'fuzzy_search', $fuzzinesText2 ), 'class' => 'dgwt-wcas-premium-only', 'type' => 'select', 'options' => array( 'off' => __( '-- Disabled', 'ajax-search-for-woocommerce' ), 'soft' => __( 'Soft', 'ajax-search-for-woocommerce' ), 'normal' => __( 'Normal', 'ajax-search-for-woocommerce' ), 'hard' => __( 'Hard', 'ajax-search-for-woocommerce' ), ), 'default' => 'normal', ); // Exclude/include products feature $settingsFields['dgwt_wcas_search'][600] = array( 'name' => 'filter_products_head', 'label' => __( 'Exclude/include products', 'ajax-search-for-woocommerce' ), 'type' => 'head', 'class' => 'dgwt-wcas-sgs-header js-dgwt-wcas-adv-settings' ); $settingsFields['dgwt_wcas_search'][625] = array( 'name' => 'filter_products_mode', 'label' => __( 'Filtering mode', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'filter_products_mode', __( 'Exclude the product group from the search results or allow search only among the indicated product group.', 'ajax-search-for-woocommerce' ) . ' ' . sprintf( $readMore, $excludeIncludeLink ), '', 'right' ), 'class' => 'js-dgwt-wcas-adv-settings', 'type' => 'select', 'options' => array( 'exclude' => __( 'Exclude', 'ajax-search-for-woocommerce' ), 'include' => __( 'Include', 'ajax-search-for-woocommerce' ), ), 'default' => 'exclude', ); $settingsFields['dgwt_wcas_search'][650] = array( 'name' => 'filter_products_rules', 'label' => __( 'Filters', 'ajax-search-for-woocommerce' ) . ' ' . Helpers::createQuestionMark( 'filter_products_rules', __( 'Filters that specify the product group and taxonomy that will be affected by the above mode', 'ajax-search-for-woocommerce' ), '', 'right' ), 'type' => 'filters_rules__premium_only', 'sanitize_callback' => array( '\DgoraWcas\Admin\SettingsAPI', 'sanitize_filters_rules__premium_only' ), 'class' => 'js-dgwt-wcas-adv-settings', 'default' => '[]', ); // Indexer feature $settingsFields['dgwt_wcas_performance'][11] = array( 'name' => 'search_engine_build', 'label' => __( 'Index status', 'ajax-search-for-woocommerce' ), 'type' => 'desc', 'desc' => Helpers::isSettingsPage() ? Builder::renderIndexingStatus() : '', 'class' => 'dgwt-wcas-premium-only wcas-opt-tntsearch' ); // Show next task description $settingsFields['dgwt_wcas_performance'][110]['desc'] = Helpers::isSettingsPage() ? Scheduler::nextTaskDescription() : ''; // Remove promo box with list of Pro features unset( $settingsFields['dgwt_wcas_performance'][0] ); } } else { // Fuzzy search feature preview $settingsFields['dgwt_wcas_search'][450] = array( 'name' => 'fuzziness_enabled_demo', 'label' => __( 'Fuzzy matching', 'ajax-search-for-woocommerce' ), 'desc' => $fuzzinesText1 . ' ' . $fuzzinesText2, 'class' => 'dgwt-wcas-premium-only', 'type' => 'select', 'options' => array( 'off' => __( '-- Disabled', 'ajax-search-for-woocommerce' ), 'soft' => __( 'Soft', 'ajax-search-for-woocommerce' ), 'normal' => __( 'Normal', 'ajax-search-for-woocommerce' ), 'hard' => __( 'Hard', 'ajax-search-for-woocommerce' ), ), 'default' => 'off', ); // Indexer feature preview $settingsFields['dgwt_wcas_performance'][11] = array( 'name' => 'search_engine_build', 'label' => __( 'Index status', 'ajax-search-for-woocommerce' ), 'type' => 'desc', 'desc' => Helpers::indexerDemoHtml(), 'class' => 'dgwt-wcas-premium-only wcas-opt-tntsearch' ); } if ( ! dgoraAsfwFs()->is_premium() ) { foreach ( $settingsFields as $key => $sections ) { foreach ( $sections as $keyl2 => $option ) { if ( self::isOptionPremium( $option ) ) { $settingsFields[ $key ][ $keyl2 ]['label'] = Helpers::getSettingsProLabel( $option['label'], 'option-label' ); } } } } $settingsFields = apply_filters( 'dgwt/wcas/settings', $settingsFields ); // Set defaults foreach ( $settingsFields as $sections ) { foreach ( $sections as $option ) { if ( ! empty( $option['name'] ) ) { $this->defaults[ $option['name'] ] = isset( $option['default'] ) ? $option['default'] : ''; } } } foreach ( $settingsFields as $key => $sections ) { ksort( $settingsFields[ $key ] ); } return $settingsFields; } /* * Option value * * @param string $option_key * @param string $default default value if option not exist * * @return string */ public function getOption( $option_key, $default = '' ) { $value = ''; if ( is_string( $option_key ) && ! empty( $option_key ) ) { if ( ! empty( $this->settingsCache ) ) { $settings = $this->settingsCache; } else { $settings = get_option( $this->settingSlug ); } if ( ! empty( $settings ) && is_array( $settings ) ) { $this->settingsCache = $settings; if ( array_key_exists( $option_key, $settings ) ) { $value = $settings[ $option_key ]; } else { // Catch default if ( empty( $default ) ) { foreach ( $this->defaults as $key => $defaultValue ) { if ( $key === $option_key ) { $value = $defaultValue; } } } } } } if ( $value === '' && ! empty( $default ) ) { $value = $default; } $value = apply_filters( 'dgwt/wcas/settings/load_value', $value, $option_key ); $value = apply_filters( 'dgwt/wcas/settings/load_value/key=' . $option_key, $value ); return $value; } /** * Update option * * @param string $optionKey * @param string $value * * @return bool */ public function updateOpt( $optionKey, $value = '' ) { $updated = false; if ( is_string( $optionKey ) && ! empty( $optionKey ) ) { $settings = get_option( $this->settingSlug ); $value = apply_filters( 'dgwt/wcas/settings/update_value', $value, $optionKey ); $value = apply_filters( 'dgwt/wcas/settings/update_value/key=' . $optionKey, $value ); $canUpdate = false; if ( array_key_exists( $optionKey, $this->defaults ) ) { $settings[ $optionKey ] = $value; $canUpdate = true; } if ( $canUpdate ) { $updated = update_option( $this->settingSlug, $settings ); if ( $updated ) { $this->settingsCache = array(); do_action( 'dgwt/wcas/settings/option_updated', $optionKey, $value ); } } } return $updated; } /** * Handles output of the settings */ public static function output() { $settings = DGWT_WCAS()->settings->settingsApi; include_once DGWT_WCAS_DIR . 'partials/admin/settings.php'; } /** * Restore default option value * * @param mixed $value * @param mixed $default * @param array $option * * @return mixed */ public function restoreDefaultValueForFreePlan( $value, $default, $option ) { if ( ! dgoraAsfwFs()->is_premium() ) { if ( self::isOptionPremium( $option ) ) { $value = $default; } } return $value; } /** * Check if user can see advanced settings * * @return bool */ public function canSeeAdvSettings() { $canSee = false; if ( is_bool( $this->canSeeAdvSettings ) ) { $canSee = $this->canSeeAdvSettings; } else { $settings = get_option( 'dgwt_wcas_settings_show_advanced' ); if ( ! empty( $settings ) ) { if ( $settings === 'on' ) { $canSee = true; } elseif ( $settings === 'off' ) { $canSee = false; } $this->canSeeAdvSettings = $canSee; } } return $canSee; } /** * Toggle visibility of advanced settings * Ajax endpoint * * @return void */ public function toggleAdvancedSettings() { if ( ! current_user_can( Helpers::shopManagerHasAccess() ? 'manage_woocommerce' : 'manage_options' ) ) { wp_die( - 1, 403 ); } check_ajax_referer( 'dgwt_wcas_advanced_options_switch' ); $show = ! empty( $_GET['adv_settings_value'] ) && $_GET['adv_settings_value'] === 'show' ? 'on' : 'off'; update_option( 'dgwt_wcas_settings_show_advanced', $show ); wp_send_json_success(); } /** * List searchable custom fields * Ajax endpoint * * @return void */ public function listSearchableCustomFields__premium_only() { if ( ! current_user_can( Helpers::shopManagerHasAccess() ? 'manage_woocommerce' : 'manage_options' ) ) { wp_die( - 1, 403 ); } check_ajax_referer( 'dgwt_wcas_get_custom_fields' ); $customFieldsTrans = get_transient( 'dgwt_wcas_searchable_custom_fields' ); if ( ! empty( $customFieldsTrans ) && is_array( $customFieldsTrans ) ) { wp_send_json_success( $customFieldsTrans ); } $list = Helpers::getSearchableCustomFields(); set_transient( 'dgwt_wcas_searchable_custom_fields', $list, 60 ); wp_send_json_success( $list ); } /** * List terms for filters * Ajax endpoint * * @return void */ public function searchTermsForFilter__premium_only() { if ( ! current_user_can( Helpers::shopManagerHasAccess() ? 'manage_woocommerce' : 'manage_options' ) ) { wp_die( - 1, 403 ); } check_ajax_referer( 'dgwt_wcas_get_filter_terms' ); $query = ! empty( $_POST['query'] ) ? wc_clean( wp_unslash( $_POST['query'] ) ) : ''; $type = ! empty( $_POST['type'] ) ? wc_clean( wp_unslash( $_POST['type'] ) ) : ''; // Attribute taxonomy has form: "pa:X" if ( strpos( $type, 'pa:' ) !== false ) { $type = wc_attribute_taxonomy_name_by_id( (int) str_replace( 'pa:', '', $type ) ); } if ( empty( $type ) ) { wp_send_json_success( array() ); } $args = array( 'hide_empty' => false, 'number' => 100, 'taxonomy' => $type, ); if ( ! empty( $query ) ) { $args['search'] = $query; } if ( Multilingual::isMultilingual() ) { $terms = Multilingual::getTermsInLang( $args ); } else { $terms = get_terms( $args ); } if ( empty( $terms ) ) { wp_send_json_success( array() ); } $list = array_map( function ( $term ) { return array( 'key' => $term->term_id, 'label' => $term->name, ); }, $terms ); wp_send_json_success( array_values( $list ) ); } /** * Check if a option is premium * * @param array $option * * @return bool */ public static function isOptionPremium( $option ) { $is_premium = false; if ( ! empty( $option['class'] ) && strpos( $option['class'], 'dgwt-wcas-premium-only' ) !== false ) { $is_premium = true; } return $is_premium; } /** * Force values of some settings if they depend on other settings * * @return void */ private function dependentOptions() { add_filter( 'dgwt/wcas/settings/section=form', function ( $settings ) { $text = __( "You have selected the Appearance -> Style -> Pirx option. Pirx style forces a submit button to be enabled. You can find this option a few rows below. That's why this option is blocked.", 'ajax-search-for-woocommerce' ); $settings[400]['label'] = Helpers::createOverrideTooltip( 'ovtt-pirx-submit-button', '

' . $text . '

' ) . $settings[400]['label']; return $settings; } ); // Pirx style - force options for submit button // Mark that the value of the option "mobile overlay" is forced if ( $this->getOption( 'search_style' ) === 'pirx' ) { //Submit button add_filter( 'dgwt/wcas/settings/load_value/key=show_submit_button', function () { return 'on'; } ); add_filter( 'dgwt/wcas/settings/section=form', function ( $settings ) { $settings[400]['disabled'] = true; return $settings; } ); // Value of submit button add_filter( 'dgwt/wcas/settings/load_value/key=search_submit_text', function () { return ''; } ); add_filter( 'dgwt/wcas/settings/section=form', function ( $settings ) { $settings[500]['disabled'] = true; $settings[500]['class'] = $settings[500]['class'] . ' dgwt-wcas-hidden'; return $settings; } ); // Submit background color add_filter( 'dgwt/wcas/settings/load_value/key=bg_submit_color', function () { return ''; } ); add_filter( 'dgwt/wcas/settings/section=form', function ( $settings ) { $settings[510]['disabled'] = true; $settings[510]['class'] = $settings[510]['class'] . ' dgwt-wcas-hidden'; return $settings; } ); } } /** * Clear settings cache */ public function clearCache() { $this->settingsCache = array(); } }