[Resolved] Website Critical Error While Editing HomePage

Home Forums Support [Resolved] Website Critical Error While Editing HomePage

Home Forums Support Website Critical Error While Editing HomePage

  • This topic has 13 replies, 4 voices, and was last updated 1 month ago by Leo.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #2268992
    Usman

    Hey everyone, I am working on an e-commerce store: kaptaanchappal.com.

    The site is working fine but when I try to edit the home page (https://kaptaanchappal.com/wp-admin/post.php?post=899&action=edit) it shows an error.


    There has been a critical error on this website. Please check your site admin email inbox for instructions.

    Learn more about troubleshooting WordPress.

    I haven’t found any email in the inbox. All other pages are editable except this. Anyone can guide me on this?

    Looking Forward,
    Usman

    #2269007
    David
    Staff
    Customer Support

    Hi there,

    ask your host to enable debugging, they should then be able to provide a more detailed error log which can be used to diagnose the issue.

    #2269188
    Usman

    Hi @David thanks for replying.

    I got the log file errors:

    Fatal error: Uncaught Error: Call to a member function is_type() on null in /home/rapixqxb/kaptaanchappal.com/wp-content/themes/generatepress/functions.php:135 Stack trace: #0 /home/rapixqxb/kaptaanchappal.com/wp-includes/class-wp-hook.php(309): {closure}(‘Select options’) #1 /home/rapixqxb/kaptaanchappal.com/wp-includes/plugin.php(191): WP_Hook->apply_filters(‘Select options’, Array) #2 /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php(60): apply_filters(‘woocommerce_pro…’, ‘Select options’, Object(WC_Product_Variable)) #3 /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/StoreApi/Schemas/V1/ProductSchema.php(477): WC_Product_Variable->add_to_cart_text() #4 [internal function]: Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema->get_item_response(Object(WC_Product_Variable)) #5 /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/BlockTypes/AbstractProductGrid.php(104): in /home/rapixqxb/kaptaanchappal.com/wp-content/themes/generatepress/functions.php on line 135

    My hosting providers asked me to consult with the theme providers.

    Looking Forward,

    #2269197
    David
    Staff
    Customer Support

    If you look at the error stack, the last line points to:

    wp-content/themes/generatepress/functions.php on line 135

    So thats line 135 of the Themes functions.php file.
    But as you can see here:

    https://github.com/tomusborne/generatepress/blob/master/functions.php

    The themes functions.php has only 122 lines. Which means that your functions.php has been modified on your site.
    And i assuMe its the code that has been added there is breaking your site.

    Can you remove any additional code ?

    #2269446
    Usman

    The rest of code is:

    
    function wplook_activate_gutenberg_products($can_edit, $post_type){
    	if($post_type == 'product'){
    		$can_edit = true;
    	}
    	
    	return $can_edit;
    }
    add_filter('use_block_editor_for_post_type', 'wplook_activate_gutenberg_products', 10, 2);
    
    add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
    	global $product;
    	if ( $product->is_type( 'variable' ) ) {
    		$text = $product->is_purchasable() ? __( 'Size', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
    	} else {
                    $text = $product->is_purchasable() ? __( 'Buy Now', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
            }
    	return $text;
    }, 10 );

    135 line is
    if ( $product->is_type( 'variable' ) ) {

    #2269524
    Leo
    Staff
    Customer Support

    You will need to remove your custom code so the function.php file is exactly the same as the original file:
    https://github.com/tomusborne/generatepress/blob/master/functions.php

    Your filter code above can be added using one of these methods:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #2269825
    Usman

    Thanks, @Leo for the recommendation. I did it and now getting this error:

    Fatal error: Uncaught Error: Call to a member function is_type() on null in /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()’d code:12 Stack trace: #0 /home/rapixqxb/kaptaanchappal.com/wp-includes/class-wp-hook.php(309): {closure}(‘Select options’) #1 /home/rapixqxb/kaptaanchappal.com/wp-includes/plugin.php(191): WP_Hook->apply_filters(‘Select options’, Array) #2 /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php(60): apply_filters(‘woocommerce_pro…’, ‘Select options’, Object(WC_Product_Variable)) #3 /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/StoreApi/Schemas/V1/ProductSchema.php(477): WC_Product_Variable->add_to_cart_text() #4 [internal function]: Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema->get_item_response(Object(WC_Product_Variable)) #5 /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/BlockTypes/Abs in /home/rapixqxb/kaptaanchappal.com/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()’d code on line 12

    #2269834
    Fernando
    Customer Support

    Hi Usman,

    To clarify, if you temporarily disable/remove this code you have here: https://generatepress.com/forums/topic/website-critical-error-while-editing-homepage/#post-2269446, does the error still exist?

    Kindly let us know.

    #2270129
    Usman

    Hey @Fernando, thanks for the suggestion.

    If I remove the code, it works fine. I was wondering if there is a way I can keep this code!

    For now, I removed it.

    #2270193
    David
    Staff
    Customer Support

    Try changing this:

    add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
    	global $product;
    	if ( $product->is_type( 'variable' ) ) {
    		$text = $product->is_purchasable() ? __( 'Size', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
    	} else {
                    $text = $product->is_purchasable() ? __( 'Buy Now', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
            }
    	return $text;
    }, 10 );

    to:

    add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
            if ( is_admin() ) {
                return; 
            }
    	global $product;
    	if ( $product->is_type( 'variable' ) ) {
    		$text = $product->is_purchasable() ? __( 'Size', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
    	} else {
                    $text = $product->is_purchasable() ? __( 'Buy Now', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
            }
    	return $text;
    }, 10 );

    And please this article on how to add PHP to your site:

    https://docs.generatepress.com/article/adding-php/

    If you continue to add the code to the parent themes functions.php they you will not be able to update the theme without losing that code.

    #2270482
    Usman

    Thank you @David for your efforts.

    I did the above and in this way, I can edit that page but when I view it, it shows an error.

    It seems like I need to delete that code only.

    #2270493
    David
    Staff
    Customer Support

    Are you using Woocommerce blocks on that page ?

    #2277783
    Usman

    Hey everyone, pardon me for the late reply.

    I removed the code and everything is working fine. I can bear this.

    But, can you guys assist me in setting up my homepage properly?

    I want to display products category wise as https://kaptaanchappal.com but the problem is, the previous imported settings look nice but I tried the Woo widget at down that is not appealing much.

    How can I display the products are GP does but category wise?

    Will be thankfull.

    #2278094
    Leo
    Staff
    Customer Support

    Can you open a new topic for the separate question?

    I’ll mark this one resolved.

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.