Ready to get started?Download WordPress


PHP Function how to duplicate functio without redeclare error (2 posts)

  1. culture-cross
    Posted 11 months ago #

    Hello there!!

    I am using a function to add tabs to a product page on my site, culture-cross.org

    I added one tab using a function. I want to add two tabs. So When I add the function again to function.php to make the second tab, I get this error:
    Fatal error: Cannot redeclare woo_new_product_tab() (previously declared in /hermes/bosoraweb183/b1660/ipg.culturecrossorg1/test/wp-content/themes/MayaShop_WordPress_Theme/maya/functions.php:46) in /hermes/bosoraweb183/b1660/ipg.culturecrossorg1/test/wp-content/themes/MayaShop_WordPress_Theme/maya/functions.php on line 78

    How do I add the function twice, to use it again?

    This is the function:

    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
    // Adds the new tab
    $tabs['test_tab'] = array(
    'title' => __( 'Ask a question', 'woocommerce' ),
    'priority' => 50,
    'callback' => 'woo_new_product_tab_content'

    return $tabs;

    function woo_new_product_tab_content() {

    // The new tab content

    echo '<h2>Have a question? Just ask!</h2>';
    echo do_shortcode('[customcontact form=5]');


    THANK YOU!!!

  2. vtxyzzy
    Posted 11 months ago #

    I think you can get what you want by adding a second filter with a different function name:

    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab2' );
    function woo_new_product_tab2( $tabs ) {
       // rest of code the same

    You could also add the second tab inside the first function, but this way keeps the code separate.


You must log in to post.

About this Topic