• Resolved Truefire

    (@truefire)


    I am attempting to remove the related products at the bottom of my single product pages. I am told there is a string of code that can be added or manipulated in the functions.php files of a child theme. Therein lies one of the issues.

    I have downloaded a plugin -Orbisius child theme creator- and have created a child theme of the theme I am running. Within the editor, one is able to view both theme’s code- the ‘child and parent’ side by side. I do not see a functions.php file for the child theme. There is none.

    There are only three files there and they are: style.css, footer.php and header.php

    Furthermore, I have looked at the code in the functions.php of the parent theme and although the file and code is there, there is no such creature as follows:

    remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 );

    I’ve hunted high and low for the single product summary and its simply not there in the functions.php

    Furthermore, if this string of code is ever entered into the child theme, how would the adjustments stick whenever I swap back over to the original theme?

    Thanks

    https://www.ads-software.com/plugins/woocommerce/

Viewing 15 replies - 1 through 15 (of 29 total)
  • Make a file called functions.php on your hard disk and put the above remove_action snippet in it. Use a plain text editor or a code editor. PHP code should start with the line:

    <?php

    Next, upload the file to:
    wp-content/themes/my-child-theme-name/functions.php using FTP or your host’s file manager software.

    Suggest you don’t alter functions.php in the parent theme, as edits will be overwritten when you update the parent theme.

    The adjustments won’t stick if you switch to the parent theme, this is intentional.

    If you get a white screen after you have added functions.php, its likely you have made a syntax error in it. There are php syntax checking services on the web.

    Thread Starter Truefire

    (@truefire)

    I’m trying my best to see what it is that you are saying but I am only understanding partly, unfortunately. Would I need to copy all of my code from my parent theme over into a created child theme first and activate that as my ‘new’ theme? I am not presently running a child theme. Would this need to be done in order to advance to the portion you are advising on?

    Then, -I’m sorry but I am not totally clear on <?php

    attache to the snippet in what fashion?
    and insert the entire string where at exactly within the functions.php?

    thanks for everything

    I am not presently running a child theme. Would this need to be done in order to advance to the portion you are advising on?

    Yes.

    Would I need to copy all of my code from my parent theme over into a created child theme first and activate that as my ‘new’ theme?

    No. As long as the template line in the child theme’s style.css references the parent theme’s directory, that’s the minimum that you need to run a child theme. Nothing else.

    However, this now makes it possible to make a file called functions.php in the child theme’s directory. This functions.php can contain the code that you want to customise your child theme. In your case, it would contain only:

    <?php
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

    As your site develops over time, you may want to add other bits of code to functions.php.

    When WordPress runs, it will run whatever’s in the parent theme’s functions.php and then whatever is in the child theme’s functions.php, if it exists. That way the two are separate and the parent theme can be updated from time to time.

    Thread Starter Truefire

    (@truefire)

    Lorro, first off- Thank you!

    No. As long as the template line in the child theme’s style.css references the parent theme’s directory, that’s the minimum that you need to run a child theme. Nothing else.

    Whenever I activated my child theme earlier there was no code at all seen in either of the text spaces of the three tabs provided. I cannot recall at this time what those three tabs were. I do believe one of them was style.css but even so, there was no code within the ‘text space’ when i clicked on any of those tabs. Not sure there.

    Could you clarify: ‘template line’ referencing parent theme directory? What does such a reference look like? Sorry, I am just not familiar. Certain code language?? thanks

    Reason I asked about ‘copying all of my code’ over into my child theme is that it appears that I would lose all of my ‘fine tuned’ adjustments and amendments done to the site whenever I switch over to a child theme. Last time I activated the child theme, it seemed like I lost all of those amendments. I would have to take a closer look however.

    Make a file called functions.php on your hard disk and put the above remove_action snippet in it. Use a plain text editor or a code editor. PHP code should start with the line:

    To create this functions.php, just use wordpad, is that correct? Upload the file in the appropriate directory so that I land where all of the other three tabs are for the child’s theme? correct? This would enable me to be able to have now a ‘fourth’ tab labeled functions.php, is that correct?

    WordPress knows what to do with this file I am assuming if I upload it into that sector.

    there was no code within the ‘text space’ when i clicked on any of those tabs.

    There wouldn’t be anything, a child theme is a new theme, with the advantage that you can add custom code that won’t be overwritten by any update of the parent theme.

    ‘template line’ referencing parent theme directory?

    style.css for the child theme contains, at its top:
    /*
    Theme Name: Twenty Fifteen Child
    Template: twentyfifteen
    <other stuff>
    */
    where the entry against Theme Name is a unique name for your child theme, and the entry against Template: is the directory name for the parent theme. See:
    https://codex.www.ads-software.com/Child_Themes
    for full details of the stylesheet header. The other lines in the stylesheet header are good practice.

    it appears that I would lose all of my ‘fine tuned’ adjustments and amendments done to the site whenever I switch over to a child theme.

    Yep, that’s the price to pay for being able to add custom code without it being overwritten by a parent theme update. If its any consolation it’ll be quicker to setup next time around.

    To create this functions.php, just use wordpad, is that correct? Upload the file in the appropriate directory

    Yes.

    This would enable me to be able to have now a ‘fourth’ tab labeled functions.php, is that correct?

    Probably not. I don’t know exactly what software you are using for the tabs. You may need to keep your primary copy of the child theme’s functions.php on your local disk and upload it each time you alter it.

    There’s other software out there that makes this task easier: html-kit, notepad++, codeanywhere, and many more, but you can go there later when you get the hang of it.

    WordPress knows what to do with this file I am assuming if I upload it into that sector.

    Yes, WordPress will:
    – look at the template directory name in the child theme stylesheet header
    – run functions.php for the parent theme (parent = template)
    – run functions.php for the child theme, if it exists

    Thread Starter Truefire

    (@truefire)

    OMG!!! Thank you so much for all of your help. I really appreciate such a helpful, thorough response. Very generous of you to help me out of this jam.

    I am not utilizing any software on my computer to build the wordpress site, I am using godaddy..its all hosted there. Created and began the process using their one button WordPress start-up feature. Thus, I would have to upload that functions.php onto their server.

    wp-content/themes/my-child-theme-name/functions.php

    If I place this functions.php into the appropriate folder as you have advised, that is all that is needed on my part? WordPress will just notice the file and respond accordingly. Seems almost too simple…thinking it should involve more. ~crossed fingers~

    One other thing, if you have a second? My background on the child theme will not change to black as I have the parent theme’s background set. I have tried numerous times. The black color is chosen under ‘appearance > background’ and under ‘appearance > customize > background image’, I have that set to no image.

    Emptying all browser cache and refreshing allows me to view the black background color as the site is loading but when it loads completely, a default color overides and stays. When I navigate back to those settings that I just mentioned, the black color is still chosen…not sure what is going on. Could you possibly advise, if you would not mind?

    If I place this functions.php into the appropriate folder as you have advised, that is all that is needed on my part? WordPress will just notice the file and respond accordingly. Seems almost too simple.

    Yes its good. But if your site whites-out then its likely you have made a syntax error in functions.php. In this case delete it. There are php syntax checkers on the net.

    Re the background, please post the url to your site.

    Thread Starter Truefire

    (@truefire)

    There is a background image. I note you have set it to “no image” but for some reason that setting has not taken effect. A fix would be to set the property explicitly in your custom css:

    body {background-image:none}

    Without the image, the black will shine through ??

    I’m not familiar with your theme. Some themes have the facility to enter custom css. This may be at Appearance > Customise or Appearance > Theme Options. It may be called Custom CSS or Advanced Settings.

    Alternatively, your plugin: Orbisius child theme creator may give you access to the child theme’s style sheet in one of the tabs.

    If your theme and the plugin do not have this feature, you can use a plugin like this one:
    https://www.ads-software.com/plugins/simple-custom-css/

    Thread Starter Truefire

    (@truefire)

    This is what the body tag reads inside of my child theme’s header.php file.

    <body <?php body_class(); ?>>

    I could not find any body tag inside of the style.css section. Should I just remove the <?php body_class(); ?> and replace with what you have provided? Or no?

    body {background-image:none}

    Thanks for helping me out so much!! I’m about to have this beat…LOL!!

    I suggest you don’t edit header.php. Its not the right place for css.

    You should not edit your theme’s style.css because this file will be overwritten by the next theme update.

    Some themes have the facility to enter custom css. This may be at Appearance > Customise or Appearance > Theme Options. It may be called Custom CSS or Advanced Settings.

    If your theme does not have this feature, you can use a plugin like this one:
    https://www.ads-software.com/plugins/simple-custom-css/

    kellyalan

    (@kellyalan)

    Following up on this — for my site using the woocommerce plugin:

    https://www.biology4teachers.com/product/the-case-of-the-tell-tale-gene/

    on the bottom of the page is a list of additional products

    I have a child theme functions.php file

    in that file I put:
    remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 );

    and uploaded it via FTP but the additional products section didn’t disappear

    am I using the wrong function code to remove that section?

    @kellyalan
    That’s the wrong code in your case because those are not the usual related products, they are coming from something in your theme called a chunkyfooter which contains a products widget. I am not familiar with your theme but its likely that there will be a place within your settings where you can remove the widget. It may be in Appearance > Widgets, or in Theme Options. Its unlikely that you will need php code to remove it.

    kellyalan

    (@kellyalan)

    Thanks for the reply – Try as I might, I can’t find the widget that’s giving me the issue. I thought it’d be in WooCommerce Products — something like when I set up a product, I unclick “show additional products” or something like that but there’s no option like that.

    I’ll keep looking =)

    Meanwhile try this in your custom css to hide it:

    #chunkyfooter {display:none}

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘Removing related products on single product page’ is closed to new replies.