This is correct. Just keep your code outside the BEGIN and END markers and you are fine.
For more information, please review this link:
http://www.childthemeconfigurator.com/how-to-use/#child_from_modified_parent
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;
}
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!
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 7 years, 11 months ago by
lilaeamedia.
Hi, thanks. But, if I add that conditional code to the parent theme, won’t I lose it when updating the theme? Thanks!
You are correct. I was simply demonstrating how it looks.