This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Search box swapping

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #37051
    msamavi64msamavi64
    Participant

    Hello,

    I have replaced the WooCommerce default search with Ajax Search Pro. The problem is that every other time the default search bar is displayed. If you would like to see the issue, please visit opars.com products pages.

    I have cleared my browser, the website and the server caches several times!

    Any resolution would be appreciated.

    Kind regards,
    Majid

    #37055
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi Majid,

    Thank you for the details!

    I have tried a couple of products, but all seem to have the default search bar instead of ajax search pro. It does not seem like a cache issue, but I suspect the product pages may use different headers as the home/search page.
    If you are using a theme builder of some sort, check the product page headers template, it is very likely different. If it was the same, te same output would be displayed on the home and product pages.

    #37056
    msamavi64msamavi64
    Participant

    Hi,

    I am using Flatsome theme.
    There is only one header for all pages.

    Any other idea, please?

    Best,
    Majid

    #37057
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Have you replaced it manually in the theme editor, or using code or..?

    #37058
    msamavi64msamavi64
    Participant

    Used ASP settings. Please see attached screenshot

    #37060
    Ernest MarcinkoErnest Marcinko
    Keymaster

    That should work, unless there is some sort of a custom code or a different plugin overriding the search.

    You can try a custom code to forcefully deregister the flatsome search shortcode, and replace it with ASP. Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    function search_shortcode2($atts) {
    	extract(shortcode_atts(array(
    		'size' => 'normal',
    		'style' => '',
    		'class' => '',
    		'visibility' => ''
    	), $atts));
    
    		$classes	= array( 'searchform-wrapper' , 'ux-search-box', 'relative' );
    		
    		if( $class ) $classes[] = $class;
    		if( $visibility ) $classes[] = $visibility;
    		if( $style ) $classes[] = 'form-'.$style;
    		if( $size ) $classes[] = 'is-'.$size;
    		$classes = implode(' ', $classes);
    
        ob_start();
    
        echo '<div class="'. $classes. '">';
    	 	echo do_shortcode('[wd_asp id=1]');
     	echo '</div>';
     	
     	$content = ob_get_contents();
        ob_end_clean();
        return $content;
    }
    remove_shortcode("search");
    add_shortcode("search", "search_shortcode2");
    #37062
    msamavi64msamavi64
    Participant

    Hi,

    Thanks for the code, but still the default search bar is randomly displayed instead of ASP!

    #37064
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Can you please add temporary FTP and back-end access? I will debug the code to see what is happening. It is probably a theme/3rd partys code issue, but I will double check.

    #37066
    msamavi64msamavi64
    Participant

    You cannot access this content.

    #37075
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Thanks!

    Looks like it was some sort of an issue with the theme registering the shortcode too early, and no other shortcodes could be registered at that time. Interestingly it only happened in some cases.

    It seems like this variation to the code has resolved the issue:

    // Replaces Flatsome searhbar with ASP
    function search_shortcode2($atts) {
    	extract(shortcode_atts(array(
    		'size' => 'normal',
    		'style' => '',
    		'class' => '',
    		'visibility' => ''
    	), $atts));
    
    		$classes	= array( 'searchform-wrapper' , 'ux-search-box', 'relative' );
    		
    		if( $class ) $classes[] = $class;
    		if( $visibility ) $classes[] = $visibility;
    		if( $style ) $classes[] = 'form-'.$style;
    		if( $size ) $classes[] = 'is-'.$size;
    		$classes = implode(' ', $classes);
    
        ob_start();
    
        echo '<div class="'. $classes. '">';
    	 	echo do_shortcode('[wd_asp id=1]');
     	echo '</div>';
     	
     	$content = ob_get_contents();
        ob_end_clean();
        return $content;
    }
    
    remove_shortcode("search");
    add_action( 'plugins_loaded', 'my_plugin_override1' );
    function my_plugin_override1() {
        // your code here
    	remove_shortcode("search");
    	add_shortcode("search", "search_shortcode2");
    }

    Although I still recommend investigating if you have any type of object cache active, to make sure the issue is not replicated.

    #37077
    msamavi64msamavi64
    Participant

    Have you implemented the code?
    On my side, nothing has changed and the issue still exists!

    #37079
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Yes. On my end everything seems to work.

    This is definitely not an issue with the plugin (and very likely not an issue with the theme either), it is not possible for the same code to execute with the same parameters and have different outputs.

    The same pageview is giving different outputs, and that is not possible – unless there something in the middle, which changes the output at will – like a cache plugin, CDN or something on the server side – check opcode cache, other type of opcache, memcached and similar modules.

    I could only replicate this one time – on the first pageview the old search was there, on the second (and every pageview afterwards) the new search. Even when I edited the theme code to not show anything, it had no effect – so some sort of a cache on the server side is present.

    #37080
    msamavi64msamavi64
    Participant

    I cleaned all caches on my computer and on the server, but still the same issue!

    #37082
    msamavi64msamavi64
    Participant

    Tried Gtmetrix using this link:

    https://www.opars.com/shop/persian-book/pardahnishinan-i-%ca%bbahd-i-nas%cc%a3iri/

    The same issue exists on its preview!

    #37085
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Don’t worry, I will investigate this further in a minute, and let you know.

Viewing 15 posts - 1 through 15 (of 22 total)
  • You must be logged in to reply to this topic.