• Resolved webdevloper21

    (@webdevloper21)


    Hi I am facing error when access the woocommerece setting
    Fatal error: Uncaught Error: Cannot use object of type WC_Settings_CYP as array in /home/customer/www/gildan1.sg-host.com/public_html/wp-content/plugins/fluid-checkout/inc/admin/admin.php:48 Stack trace: #0 /home/customer/www/gildan1.sg-host.com/public_html/wp-includes/class-wp-hook.php(303): FluidCheckout_Admin->add_settings_pages(Object(WC_Settings_CYP)) #1 /home/customer/www/gildan1.sg-host.com/public_html/wp-includes/plugin.php(189): WP_Hook->apply_filters(Object(WC_Settings_CYP), Array) #2 /home/customer/www/gildan1.sg-host.com/public_html/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-settings.php(62): apply_filters('woocommerce_get...', Array) #3 /home/customer/www/gildan1.sg-host.com/public_html/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-menus.php(125): WC_Admin_Settings::get_settings_pages() #4 /home/customer/www/gildan1.sg-host.com/public_html/wp-includes/class-wp-hook.php(303): WC_Admin_Menus->save_settings('') #5 /home/customer/www/gildan1.sg-host.com/public_html/wp-includes/cla in /home/customer/www/gildan1.sg-host.com/public_html/wp-content/plugins/fluid-checkout/inc/admin/admin.php on line 48

    Could you help?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter webdevloper21

    (@webdevloper21)

    FYI, when I add this line
    $settings = json_decode(json_encode($settings), true);
    in this file
    \wp-content\plugins\fluid-checkout\inc\admin\admin.php
    the error will be fix.

    if any other solution then please update here as well as in plugin.

    Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @webdevloper21,

    The WooCommerce $settings parameter is supposed to be of type Array instead of WC_Settings_CYP, it is likely that another plugin or theme is incorrectly changing that parameter type.

    Please check on your website for the plugin which defines the class WC_Settings_CYP, and contact the plugin author to check and fix this issue on their end.

    To prevent the “Fatal Error” we’ve added verification of the $settings parameter type on our plugin as seen below, which will be available in the next update (v.1.2.6):

    /**
     * Add new WooCommerce settings pages/tabs.
     */
    public function add_settings_pages( $settings ) {
    	// Bail if settings not an array
    	if ( ! is_array( $settings ) ) { return $settings; }
    
    	$settings[] = include self::$directory_path . 'inc/admin/admin-settings-wc-shipping.php';
    	$settings[] = include self::$directory_path . 'inc/admin/admin-settings-checkout.php';
    	
    	return $settings;
    }

    This change will prevent the “Fatal Error” but will also make the Fluid Checkout settings unavailable. We’ve also added this information on the readme.txt.

    Best,
    Diego

    Thread Starter webdevloper21

    (@webdevloper21)

    Why you are not using this $settings = json_decode(json_encode($settings), true); as with this line we could access plugin setting also ?

    Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @webdevloper21,

    The solution proposed is not ideal. The reasoning is that the $settings parameter is supposed to be an array, not anything else.

    Whenever add_filter is used, it is expected that the return value has the same type as the passed-in parameter.

    Check the WooCommerce variable declaration and the correct way of adding new features to these settings in the WooCommerce code at:
    https://github.com/woocommerce/woocommerce/blob/trunk/includes/admin/class-wc-admin-settings.php#L48

    Adding the json_encode and json_decode will make the plugin unnecessarily slower (probably by just a few milliseconds), and can potentially break something else.

    We believe bugs should be fixed at their “root” cause, otherwise, the “weeds” will keep growing over time.

    If you do not have the option to look into the conflicting plugin and contact their respective developers, you can still unhook the Fluid Checkout’s function add_settings_pages and hook a modified version of it. Although we strongly discourage that.

    Best,
    Diego

    Thread Starter webdevloper21

    (@webdevloper21)

    How do I do that? could you please give me code(hook) to add in function.php ?

    Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @webdevloper21,

    Again, we strongly discourage the use of this method for the reasons mentioned on this thread…

    The hook is woocommerce_get_settings_pages, here is the code to remove the Fluid Checkout hooked function:

    
    if ( class_exists( 'FluidCheckout_Admin' ) ) {
    	remove_filter( 'woocommerce_get_settings_pages', array( FluidCheckout_Admin::instance(), 'add_settings_pages' ), 50 );
    }
    

    After that, you can hook in your modified version of the function, which code will depend on your implementation.

    Best,
    Diego

    Plugin Author Diego Versiani

    (@diegoversiani)

    Hi @webdevloper21,

    I’ve just released a new version (1.2.7) that should fix the “fatal error” and still display the plugin’s settings.

    I’m closing this thread for now. Few free to re-open it if you still experience this issue.

    Best,
    Diego

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Notice Error while accessing wooocommerce setting’ is closed to new replies.