• Resolved gamshoro

    (@gamshoro)


    Hi,

    Is there any option to disable currency switcher bar on some specific pages?

    Like, I don’t want to show currency switcher bar on CONCTACT US page.

    After enabling the design, it’s showing sidebar on every page of website.

    I shall be very thankful.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,
    Please add this to Conditional tags/Other pages in the plugin settings/Design:
    !is_page('contact-us')
    If CONCTACT US page slug is different, please change ‘contact-us’ with the page ID or slug.
    Best regards

    Thread Starter gamshoro

    (@gamshoro)

    How can I add multiple pages?

    You can create a really simple “Must Use” plugin that lists the pages you want CURCY to be active on.

    I had the same issue as I needed much finer control of where to have the plugin active, and created the MU Plugin below.

    You need only edit $allowed_paths – the first variable in the script. The code is self-documenting. Let me know if it works for you, it does for me ??

    <?php
    /*
    	Curcy filter
    	- Fine control over where the CURCY plugin is displayed.
    	- This code is based on the superb article from Kinsta below (due thanks and respect there!)
    	- Place this file in wp-content/mu-plugins 
    		-- The file can have any name, but curcy-control.php is good choice.
    		
    	Ref: 
    		- https://kinsta.com/blog/disable-wordpress-plugins-loading/
    	
    	Last Update: 18.02.2022
    */
    
    /*	-- -- -- CONFIGURATION START -- -- --*/
    /*
    	Below you need to specify a list of URL paths where CURCY plugin SHOULD be loaded.
    	For example:
    		https://mysite.com/shop/ has allowed path of 'shop'
    		https://mysite.com/cart/ has allowed path of 'cart'
    		
    */	
    	$allowed_paths = array("shop","pricing","cart","basket","product","checkout");
    
    /* -- -- -- -- CONFIGURATION END -- -- -- */
    
    // Get path i.e. after web server name
    $current_page_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    
    // Find out if user is accessing admin panel. If not, then can enable plugin filter safely.
    $is_admin= (strpos($current_page_path, '/wp-admin/')) ? true: false;
    
    // If not admin panel ...
    if( false === $is_admin ){
    	add_filter( 'option_active_plugins', function( $plugins ){
    		
    		// Get this variable defined outside the function.
    		global $current_page_path;
    
    		/*
    			Work out if on home page, which will not have anything after the server name. Little bit of a hack!:-)
    			- Not used in the code below but if you need CURCY on the home page, you might need to do some homepage detection.
    		*/	
    		$onhomepage = false;
    		if  ( ($current_page_path == '/') || ($current_page_path == '')){
    			$onhomepage = true;
    		}		
    
    		
    		/* 
    			- We create an array to holding active plugins that should be removed from the current post/page.
    			- This only holds the CURCY plugin but you can add more plugins to remove if desired.
    			
    			- Refer to the KINSTA article reference at the start of this code to find out, easily, how 
    				to get the plugin path and name you see below.
    		*/
    		$plugins_to_remove = array();
    		$plugins_to_remove [] =  "woo-multi-currency/woo-multi-currency.php";
    
    		// Set a default flag to remove the CURCY plugin. 
    		$remove_CURCY = true; 
    
    		/*
    			Now cycle through allowed_paths and see if any match the current page. 
    			If so, set the 'remove_CURCY' flag to false and break out the allowed_paths loop.
    		*/	
    		global $allowed_paths;	// Pick up the paths from outside this function, set at the start.
    		foreach ($allowed_paths as $allowed_path) {
    			// Syntax: if (some condition) value if true : value if false
    			$is_allowed_page = (strpos($current_page_path, $allowed_path)) ? true: false; 
    			if ($is_allowed_page){
    				$remove_CURCY = false;
    				break;
    			} 
    		  }
    		
    		/* Remove CURCY (or not :-) */		
    		if  ( $remove_CURCY == true ) {
    			$plugins = array_diff( $plugins, $plugins_to_remove);	
    		}
    	
    
    	// Finally return the filtered list of active plugins for this page/post, with CURCY removed if desired.
    	return $plugins;
    
    	} );
    
    }
    
    ?>
    
    • This reply was modified 2 years, 9 months ago by Duncan.
    • This reply was modified 2 years, 9 months ago by Duncan.
    • This reply was modified 2 years, 9 months ago by Duncan.

    Oops! Minor bug in my reply above which I can no longer edit. Here’s the code without the bug, sorry.

    <?php
    /*
    	Curcy filter
    	- Fine control over where the CURCY plugin is displayed.
    	- Removes from all pages/posts except those specified in line 25 below.
    	- Place this file in wp-content/mu-plugins 
    		-- The file can have any name, but curcy-control.php is good choice.			
    	- This code is based on the superb article from Kinsta below (due thanks and respect there!)
    
    	Ref: 
    		- https://kinsta.com/blog/disable-wordpress-plugins-loading/
    	
    	Last Update: 18.02.2022
    */
    
    /*	-- -- -- CONFIGURATION START -- -- --*/
    /*
    	Below you need to specify a list of URL paths where CURCY plugin SHOULD be loaded.
    	For example:
    		https://mysite.com/shop/ has allowed path of 'shop'
    		https://mysite.com/cart/ has allowed path of 'cart'
    		
    */	
    	$allowed_paths = array("shop","pricing","cart","basket","product","checkout");
    
    /* -- -- -- -- CONFIGURATION END -- -- -- */
    
    // Get path i.e. after web server name
    $current_page_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    
    // Find out if user is accessing admin panel. If not, then can enable plugin filter safely.
    $is_admin= (strpos($current_page_path, 'wp-admin')) ? true: false;
    
    // If not admin panel ...
    if( !$is_admin ){
    	add_filter( 'option_active_plugins', function( $plugins ){
    		
    		// Get this variable defined outside the function.
    		global $current_page_path;
    
    		/*
    			Work out if on home page, which will not have anything after the server name. Little bit of a hack!:-)
    			- Not used in the code below but if you need CURCY on the home page, you might need to do some homepage detection.
    		*/	
    		$onhomepage = false;
    		if  ( ($current_page_path == '/') || ($current_page_path == '')){
    			$onhomepage = true;
    		}		
    
    		
    		/* 
    			- We create an array to holding active plugins that should be removed from the current post/page.
    			- This only holds the CURCY plugin but you can add more plugins to remove if desired.
    			
    			- Refer to the KINSTA article reference at the start of this code to find out, easily, how 
    				to get the plugin path and name you see below.
    		*/
    		$plugins_to_remove = array();
    		$plugins_to_remove [] =  "woo-multi-currency/woo-multi-currency.php";
    
    		// Set a default flag to remove the CURCY plugin. 
    		$remove_CURCY = true; 
    
    		/*
    			Now cycle through allowed_paths and see if any match the current page. 
    			If so, set the 'remove_CURCY' flag to false and break out the allowed_paths loop.
    		*/	
    		global $allowed_paths;	// Pick up the paths from outside this function, set at the start.
    		foreach ($allowed_paths as $allowed_path) {
    			// Syntax: if (some condition) value if true : value if false
    			$is_allowed_page = (strpos($current_page_path, $allowed_path)) ? true: false; 
    			if ($is_allowed_page){
    				$remove_CURCY = false;
    				break;
    			} 
    		  }
    		
    		/* Remove CURCY (or not :-) */		
    		if  ( $remove_CURCY == true ) {
    			$plugins = array_diff( $plugins, $plugins_to_remove);	
    		}
    	
    
    	// Finally return the filtered list of active plugins for this page/post, with CURCY removed if desired.
    	return $plugins;
    
    	} );
    
    }
    
    ?>
    

    @gamshoro, sorry for missing your reply, please follow this guide https://villatheme.com/knowledge-base/conditional-tags/#:~:text=Displaying%20on%20specific%20pages

    @duncan1967, thank you for the code. However, it’s not the appropriate solution in this case as the code disables the entire plugin on specific pages. The topic owner only needs to disable the currency sidebar, other functionalities(such as currency selector shortcode/widget…) should be still working properly.

    Best regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Disable Currency Bar on Specific Page’ is closed to new replies.