• Resolved Infotam

    (@infotam)


    Hi!

    I have some custom functions related to woocommerce in my current theme. As I don’t want to lose that customizations when updating the theme, I have installed your plugin and I want to transfer that code to the child theme that has been created. I wanted to know if I just need to paste that custom code below the code that appears at the child theme functions.php, just below the sentence // END ENQUEUE PARENT ACTION

    I’m looking forward to hearing from you soon.

    Thanks a lot!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author lilaeamedia

    (@lilaeamedia)

    This is correct. Just keep your code outside the BEGIN and END markers and you are fine.

    For more information, please review this link:

    https://www.childthemeconfigurator.com/how-to-use/#child_from_modified_parent

    Thread Starter Infotam

    (@infotam)

    Hi, thank you very much for your explanation. In the documentation you have send me, it is said something about functions not always working in the child theme. Could you tell me if this kind of functions (related to Woocommerce) would work properly in a child theme? Thanks!

    add_filter(‘woocommerce_states’, ‘my_custom_states’);

    function my_custom_states( $states ) {

    $exclude = array(‘TF’,’CE’,’GC’,’ML’);

    foreach( $exclude as $item ) {
    unset($states[‘ES’][$item]);
    }

    return $states;
    }

    add_filter( ‘woocommerce_product_tabs’, ‘remove_additional_info_tab’, 50 );
    function remove_additional_info_tab( $tabs ) {
    unset( $tabs[‘additional_information’] );
    return $tabs;
    }

    Plugin Author lilaeamedia

    (@lilaeamedia)

    These are fine.

    Thread Starter Infotam

    (@infotam)

    Thanks a lot! My last question is if it’s ok to copy that code in the child theme while it is still working on the parent theme. Should I erase it first or it doesn’t matter? Thanks!

    Plugin Author lilaeamedia

    (@lilaeamedia)

    PHP will throw a FATAL “duplicate function” error if the function exists in both functions files and the child theme is activated.

    EITHER:

    1. Delete it from the parent theme before adding it to the child theme
    2. Wrap the parent theme version in a conditional “if ( !function_exists( “[function]” ) )” where [function] corresponds to the function name.

    Example:

    if ( !function_exists( "remove_additional_info_tab" ) ):
        function remove_additional_info_tab( $tabs ) {
            unset( $tabs['additional_information'] );
            return $tabs;
        }
    endif;
    • This reply was modified 6 years, 5 months ago by lilaeamedia.
    Thread Starter Infotam

    (@infotam)

    Hi, thanks. But, if I add that conditional code to the parent theme, won’t I lose it when updating the theme? Thanks!

    Plugin Author lilaeamedia

    (@lilaeamedia)

    You are correct. I was simply demonstrating how it looks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding functions to child theme’ is closed to new replies.