• Suddenly most of my snippets stopped working. I got an email from wordpress with the following:

    /wordpress/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()’d code. Code error: Uncaught Error: Call to a member function get() on null in
    /wordpress/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()’d code:3
    Stack trace:
    #0 /wordpress/wp-includes/class-wp-hook.php(287): my_custom_available_payment_gateways_temp(Array)
    #1 /papilio.gr/wordpress/wp-includes/plugin.php(212): WP_Hook->apply_filters(Array, Array)
    #2 /wordpress/wp-content/plugins/woocommerce/includes/class-wc-payment-gateways.php(160): apply_filters(‘woocommerce_ava…’, Array)
    #3 /papilio.gr/wordpress/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Features/OnboardingTasks.php(94): WC_Payment_Gateways->get_available_payment_gateways()
    #4 /wordpress/wp-conten`

    i have updated the wordpress to latest version. i use PHP 7.3.27 and your plugin on the latest version`

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @iliaspavlou,

    The error message indicates that this is coming from a WooCommerce snippet, likely one where you are adjusting something about the available payment gateways.

    If you’re able to find and post that snippet’s code here, I can make some suggestions for how to fix it.

    Thread Starter iliaspavlou

    (@iliaspavlou)

    Hi,

    Below is the code

    add_filter('wfacp_print_shipping_hidden_fields','__return_false');
    function my_custom_available_payment_gateways_temp( $gateways ) {
    	$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
    	
    	// When 'COD' has been chosen as shipping rate
    	if ( in_array( '2483', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cardlink'] );
    		unset( $gateways['dc-paybybank'] );
    		unset( $gateways['bacs'] );
    		unset( $gateways['bank_transfer_1'] );
    		unset( $gateways['stripe_cc'] );
    	endif;
    
    	if ( in_array( '2565', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    		unset( $gateways['bacs'] );
    		unset( $gateways['dc-paybybank'] );
    
    	endif;
    	if ( in_array( '2609', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['bacs'] );
    		unset( $gateways['nbg_gateway'] );
    		unset( $gateways['cardlink'] );
    
    	endif;
    	if ( in_array( '2608', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    
    	endif;
    	if ( in_array( '2488', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    
    	endif;
    	if ( in_array( '2482', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    		unset( $gateways['bank_transfer_1'] );
    	endif;
    	if ( in_array( '23225', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    		unset( $gateways['bacs'] );
    		unset( $gateways['bank_transfer_1'] );
    	endif;
    	
    	if ( in_array( '2488', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['bank_transfer_1'] );
    	endif;
    
    	
    	return $gateways;
    }
    add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways_temp' );
    Plugin Author Shea Bunge

    (@bungeshea)

    Adding an if statement at the beginning of the function should prevent those errors from showing up when the WooCommerce session is not loaded:

    add_filter( 'wfacp_print_shipping_hidden_fields', '__return_false' );
    
    add_filter( 'woocommerce_available_payment_gateways', function ( $gateways ) {
    	
    	if ( ! WC()->session ) {
    		return false;
    	}
    	
    	$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
    
    	// When 'COD' has been chosen as shipping rate
    	if ( in_array( '2483', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cardlink'] );
    		unset( $gateways['dc-paybybank'] );
    		unset( $gateways['bacs'] );
    		unset( $gateways['bank_transfer_1'] );
    		unset( $gateways['stripe_cc'] );
    	endif;
    
    	if ( in_array( '2565', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    		unset( $gateways['bacs'] );
    		unset( $gateways['dc-paybybank'] );
    
    	endif;
    	if ( in_array( '2609', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['bacs'] );
    		unset( $gateways['nbg_gateway'] );
    		unset( $gateways['cardlink'] );
    
    	endif;
    	if ( in_array( '2608', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    
    	endif;
    	if ( in_array( '2488', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    
    	endif;
    	if ( in_array( '2482', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    		unset( $gateways['bank_transfer_1'] );
    	endif;
    	if ( in_array( '23225', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['cod'] );
    		unset( $gateways['bacs'] );
    		unset( $gateways['bank_transfer_1'] );
    	endif;
    
    	if ( in_array( '2488', $chosen_shipping_rates ) ) :
    		// Remove bank transfer payment gateway
    		unset( $gateways['bank_transfer_1'] );
    	endif;
    
    	return $gateways;
    } );
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘most snippets doesn’t work anymore’ is closed to new replies.