Title: Problematic Snippets
Last modified: May 29, 2023

---

# Problematic Snippets

 *  [peros](https://wordpress.org/support/users/peros/)
 * (@peros)
 * [3 years ago](https://wordpress.org/support/topic/problematic-snippets/)
 * Exactly one week ago, past Monday, we made a few updates to our website’s plugins.
   Since then a lot of problems have occured in different aspects of our website’s
   functionality and after a lot of testing this past week we concluded that most(
   if not all) of the problems originate by two specific snippets and even isolated
   the specific parts of the code responsible for the issues from those two. So,
   we noticed that in both cases we have filters that hook into ‘woocommerce_available_payment_gateways’.
 * Some of the issues created are(the most important): 
   – Unable to make any changes
   to existing snippets. We get the message “Could not update snippet. Request failed
   with status code 500”.-Cannot open Elementor Editor in any of my pages. It gets
   stuck on loading. and a message to activate safe mode appears.
 * All of the issues mentioned above get resolved when we deactivate these two snippets.
   The specific parts that I mentioned already to be exact. 
   Eveything was working
   fine beforehand and did not have any of these issues.
 * I wasn’t sure if this was the right place to post my problem but I do not know
   why it could be happening and any help would be greatly appreciated! If you would
   like to see the code let me know.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [3 years ago](https://wordpress.org/support/topic/problematic-snippets/#post-16776213)
 * Very curious! I really appreciate you reporting this and the steps necessary 
   to reproduce it. I’ll see whether I can do so, and work out a fix for this issue.
   It’s been frustrating having some users be receiving the 500 errors but not knowing
   how to track down the cause.
 *  Thread Starter [peros](https://wordpress.org/support/users/peros/)
 * (@peros)
 * [3 years ago](https://wordpress.org/support/topic/problematic-snippets/#post-16776608)
 * I hope you can work out a solution, thank you!
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [3 years ago](https://wordpress.org/support/topic/problematic-snippets/#post-16785093)
 * Would it be possible to share those two snippets causing issues?
 *  [Dimos](https://wordpress.org/support/users/dimosgeor/)
 * (@dimosgeor)
 * [3 years ago](https://wordpress.org/support/topic/problematic-snippets/#post-16797146)
 * Hi, we were collaborating with peros, but unfortunately he had to leave the project!
   Here are the parts of snippets that dont work together.
 *     ```wp-block-code
       add_filter( 'woocommerce_available_payment_gateways','disable39A');
       function disable39A( $available_gateways ) {
       	global $woocommerce;
       	 if ( ! is_admin() ) {
       	if(bbloomer_check_category_in_cart())
       	{
       		unset(  $available_gateways['pay_later'] );
       	}
       	 }
   
       	return $available_gateways;
       }
       ```
   
 *     ```wp-block-code
       add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_gateway_disable_shipping_326' );
         function bbloomer_gateway_disable_shipping_326( $available_gateways ) {
   
          if ( ! is_admin() && WC()->session ) {
   
             $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
   
             $chosen_shipping = $chosen_methods[0];
   
             if ( isset( $available_gateways['pay_later']) && 0 === strpos( $chosen_shipping, 'flat_rate:5'  )){
                unset( $available_gateways['pay_later'] );
       		   unset( $available_gateways['bacs'] );
       		   unset( $available_gateways['eurobank_gateway'] );
       		    unset( $available_gateways['bank_transfer_1'] );
       		    unset( $available_gateways['bank_transfer_2'] );
       		    unset( $available_gateways['bank_transfer_3'] );
       		    unset( $available_gateways['bank_transfer_4'] );
             }
       	    if ( isset( $available_gateways['pay_later']) && 0 === strpos( $chosen_shipping, 'flat_rate:9'  )){
                unset( $available_gateways['pay_later'] );
       		   unset( $available_gateways['bacs'] );
       		   unset( $available_gateways['eurobank_gateway'] );
       			 unset( $available_gateways['bank_transfer_1'] );
       		    unset( $available_gateways['bank_transfer_2'] );
       		    unset( $available_gateways['bank_transfer_3'] );
       		    unset( $available_gateways['bank_transfer_4'] );
             }
       	    if ( isset( $available_gateways['pay_later']) && 0 === strpos( $chosen_shipping, 'flat_rate:14'  )){
                unset( $available_gateways['pay_later'] );
       		   unset( $available_gateways['bacs'] );
       		   unset( $available_gateways['eurobank_gateway'] );
       			 unset( $available_gateways['bank_transfer_1'] );
       		    unset( $available_gateways['bank_transfer_2'] );
       		    unset( $available_gateways['bank_transfer_3'] );
       		    unset( $available_gateways['bank_transfer_4'] );
             }
   
       	    if ($chosen_shipping == 'flat_rate:10'){
       			if (is_checkout() && ! is_wc_endpoint_url()){
       	       unset( $available_gateways['pay_later'] );
       		   unset( $available_gateways['bacs'] );
       		   unset( $available_gateways['eurobank_gateway'] );
       				 unset( $available_gateways['bank_transfer_1'] );
       		    unset( $available_gateways['bank_transfer_2'] );
       		    unset( $available_gateways['bank_transfer_3'] );
       		    unset( $available_gateways['bank_transfer_4'] );
       		   }
       			else {
       			 unset( $available_gateways['other_payment'] );
       			}
       		}
       	   else {
       		    unset( $available_gateways['other_payment'] );
       	   }
   
          }
   
          return $available_gateways;
   
       }
       ```
   
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/problematic-snippets/#post-16871266)
 * Hi [@peros](https://wordpress.org/support/users/peros/), just wanted to reach
   out and check whether our v3.4.1 patch fixed this issue for you?

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Problematic Snippets’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/problematic-snippets/#post-16871266)
 * Status: not a support question