Support » Fixing WordPress » Menu Page in admin not working after update to 4.8

  • Resolved George Pattihis



    After updating to the latest version of wordpress I noticed that the page in Admin -> Appearence -> Menu is not working. I managed to narrow down the cause of the problem to a custom function

    function my_custom_available_payment_gateways( $gateways ) {
    	$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
    	if ( ! in_array( 'local_pickup_plus', $chosen_shipping_rates ) ) :
    		unset( $gateways['cheque'] );
    	if ( in_array( 'local_pickup_plus', $chosen_shipping_rates ) ) :
    		unset( $gateways['cod'] );
    	return $gateways;
    add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );

    This function filters payment gateways depending on shipping method. If I remove this function Menu page in admin returns to normal. If I add the function again menu page does not work and server logs the following errors

    #0: *2967264 FastCGI sent in stderr: “PHP message: PHP Fatal error: Uncaught Error: Call to a member function get() on null in /child-theme-path/functions.php:66
    Stack trace:
    #0 /path/wp-includes/class-wp-hook.php(298): my_custom_available_payment_gateways(Array)
    #1 /path/wp-includes/plugin.php(203): WP_Hook->apply_filters(Array, Array)
    #2 /path/wp-content/plugins/woocommerce/includes/class-wc-payment-gateways.php(165): apply_filters(‘woocommerce_ava…’, Array)
    #3 /path/wp-content/plugins/woocommerce/includes/wc-account-functions.php(115): WC_Payment_Gateways->get_available_payment_gateways()
    #4 /path/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-menus.php(242): wc_get_account_menu_items()
    #5 /path/wp-admin/includes/template.php(1170): WC_Admin_Menus->nav_menu_links(NULL, Array)
    #6 /var” while reading response header from upstream

    I had no problems with previous wordpress versions. Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Should that code be running on the admin side? If not, add this to the beginning of the function to return without executing the code:

    if ( is_admin() ) return $gateways;

    If there is an underlying issue with the code it won’t fix that, but it will solve the error since it won’t run on the Menus page. I’d also make sure you’re up to date with the newest version of WC.

    Thread Starter George Pattihis



    Thank you for your reply. Your suggestion seems to do the trick. Menu page now works properly and the function does what it is supposed to do.

    Is there a similar ‘if’ statement to run the code only when in checkout page? Because that is where the customer selects payment gateway and I have to filter available shipping methods.

    WC is in latest version 3.1.0

    Yea they’ve got an is_checkout() function and quite a few other conditionals available too.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Menu Page in admin not working after update to 4.8’ is closed to new replies.