[Support request] Lost custom code with update.

Home Forums Support [Support request] Lost custom code with update.

Home Forums Support Lost custom code with update.

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #571987
    Sami

    Hello, and sorry for bothering you guys, the issue i am having is totally my bad!
    I had a developer to write some custom code for me as i am new to building websites. The custom code was added to the parent theme and as the theme was updated all the custom code was wiped off.

    I have since done some searching and understand that custom code should be added to the child theme.
    I was smart enough to create a back up of the code and i am pretty sure i know where all the custom code is.

    I tried to create js, css and php files and i think everything else worked out except the functions file that i added to the child seems to break the website if i add the custom code in the file manager.

    If i add it to the appearance –> editor then it gives me this error.

    Your PHP code changes were rolled back due to an error on line 138 of file wp-content/themes/generatepress/functions.php. Please fix and try saving again.

    Cannot redeclare woocommerce_custom_template_loop_product_link_open() (previously declared in wp-content/themes/generatepress-child/functions.php:55)

    Any advise is highly appreciated.

    #572019
    Tom
    Lead Developer
    Lead Developer

    What that error means is you’ve previously declared that exact same function name in your child theme.

    Search for woocommerce_custom_template_loop_product_link_open within the editor, and make sure only one function exists with that name.

    Let me know if you need more info ๐Ÿ™‚

    #572028
    Sami

    Sorry, i don’t quite understand what i am supposed to do.

    I used ctl + f and found 2 instances where woocommerce_custom_template_loop_product_link_open is used.

    function woocommerce_custom_template_loop_product_link_open() {
    		global $product;
    
    		$link = apply_filters( 'woocommerce_loop_product_link', get_the_permalink(), $product );
    
    		echo '<a target="_blank" href="' . esc_url( $link ) . '">';
    }

    &

    add_action('woocommerce_before_shop_loop_item',function(){
    	
    	global $product;
    
    	if($product->get_type() == 'external'){
    
    		remove_action('woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open');
    
    		add_action('woocommerce_before_shop_loop_item','<strong>woocommerce_custom_template_loop_product_link_open</strong>',5);
    
    		add_filter('woocommerce_loop_product_link',function($product_link,$product){
    
    			return $product->get_product_url();
    
    		},3,2);
    
    	}

    I can give you access to the editor too if want and you can fix it easily that way and i won’t be stealing your time.

    #572518
    Tom
    Lead Developer
    Lead Developer

    What’s on line 55 of your child theme functions.php file?

    #572935
    Sami

    Thanks for your response

    line 55: global $product;

    #572939
    Tom
    Lead Developer
    Lead Developer

    Ah, then the code has changed since the error you shared happened.

    Feel free to send me temp login details and I’ll take a look: https://generatepress.com/contact/

    #572948
    Sami

    Sent the login info!

    #574783
    Sami

    Hello Tom, did you get my login details? Do you need me to provide some additional info?

    Thanks, Aleksi

    #575302
    Tom
    Lead Developer
    Lead Developer

    I replied to your email a few days ago.

    I checked your child theme functions.php and there was barely anything in there. Did you remove all of your custom code?

    #575324
    Sami

    Oh yeah, sorry i gave a different email so i didn’t check that one.

    Yeah i couldn’t submit the code because of the error. The custom code is all in the parent theme functions file.

    I just tried to copy that same custom code to the child theme. You can check the parent theme, it’s all there.

    Thanks for helping out.

    #575735
    Tom
    Lead Developer
    Lead Developer

    Can you share the exact code you’re adding into the child theme inside a pastebin?: https://pastebin.com/

    Then I’ll be able to inspect it and make any necessary edits ๐Ÿ™‚

    #575768
    Sami

    pastebin.com/ABtuYB75

    I am not a 100% of what the exact code is. My programmer added the code to the parent theme. So everything that is not part of the normal GP code in the parent functions.php is custom code i think. So i just basically copied the whole thing after the basic generate press code.

    All the custom code have a //txt before explaining what it does.

    #576226
    Tom
    Lead Developer
    Lead Developer

    I couldn’t really spot anything wrong, but maybe try this: https://pastebin.com/eKYaKRDT

    #576334
    Sami

    Got this message now.

    Your PHP code changes were rolled back due to an error on line 199 of file wp-content/themes/generatepress/functions.php. Please fix and try saving again.

    Cannot redeclare the_excerpt_max_charlength() (previously declared in wp-content/themes/generatepress-child/functions.php:105)

    Got this message now.

    Can i remove all the custom code from the parent theme?

    Maybe it is not working because i have the same custom code in child and parent now.

    If you want to take a look you can use the login credentials i submitted before and see if you can make sense of it.

    #576683
    Tom
    Lead Developer
    Lead Developer

    Ah yes, you need to remove all of the custom code from the parent theme before you add it to the child theme.

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