int * * @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(); } }